Hi guys,
We are using A12 version 2023.06-ext6.
In our form, there is a Deteached repeat, when clicking on Commit button to save to form detail, it always triggers validation part.
Now we want to disable the validation at that form base on roles. Example: if logged user has ADMIN role, they can save the form without validation. Or it even has an extra button on Subheader to Save without validation, and keep the Commit button as default behavior.
As we have found so far, for whatever solution, it has to customize on leaveDetachedRepeatRow action like Customizing DispatchConfiguration, but we do not seen any option like disableRepeatValidationOnLeaving is used in leaveDetachedRepeatRowMiddleware.ts to switch on/off that validatePart. This option is using in some other middlewares but not in the detached repeat one.
How can we make it in current version?
Does A12 provide this option in another version?
Thank you for any helps,
An
The possibility to model the footer button was created A12-13358.
Within version 2023.06-etx6 we can’t add new buttons in the repeat-footer. So I found a solution to custom the event of the button:
function mapDispatchToProps(dispatch: Dispatch, props: FormEngineProps): DefaultDispatchProps {
const defaultDispatchProps = FormEngineActions.mapDispatchToProps(dispatch, props);
return {
eventHandlers: {
...defaultDispatchProps.eventHandlers,
repeat: {
...defaultDispatchProps.eventHandlers.repeat,
onLeaveDetachedRepeatRow(cancel: boolean): void {
dispatch(Custom.leaveDetachedRepeatRow({ cancel }));
},
}
}
};
}
Then the middleware:
export function customLeaveDetachedRepeatRowMiddleware(
options: Conversion & Localization & Pick<MiddlewareOptions, "externalEnumerationProvider">
): Middleware {
return api => next => action => {
const result = next(action);
if (Custom.leaveDetachedRepeatRow.match(action)) { // our custom event
const { cancel: cancelDetachedScreen } = action.payload;
const formModel = ModelSelectors.modelInScene()(api.getState());
const screenLocationBeforeLeave = UiStateSelectors.currentScreenLocation()(api.getState());
const locationPath = screenLocationBeforeLeave.locationPath;
const repeatFormModelPath = ModelPath.parentPath(locationPath);
const repeat = findElementByFormModelPath(formModel, repeatFormModelPath);
if (!repeat || !FormModel.Repeat.isInstance(repeat)) {
throw new Error("Expected to get path to a repeat!");
}
if (buildYourLogic(repeat.annotation)) {
// your logic here
} else {
api.dispatch(Events.Repeat.leaveDetachedRepeatRow({ cancel: action.payload.cancel }));
}
}
return result;
};
}
We will consider the remove the custom implementation above in the next version (if it includes the possibility to model the footer button).
Regards!
Thanks Nhat,
That could be a solution, as I understand the custom code at
if (buildYourLogic(repeat.annotation)) {
// your logic here
}
would be mostly same as the A12 internal leaveDetachedRepeatRowMiddleware.ts, with a bit change at validatePart, so I concern that coping code of internal thing might bring along some internal dependencies as well, not sure how much copied, I will try.
btw I’m still looking forward to know if there is a better solution.
Since there are no better idea, I will assume Nhat’s suggestion is the most feasible solution currently. Thank you.