Find out if a full validation was successful

Heyho,

i modeled a button which triggers via Form-Engine-Event a saga that i wrote for saving an entity with an own endpoint. This button triggers a full validation.

My saga should wait until the validation is done and i want to know if it was successful or not. How should i do this ?

Best regards,
Tjorben

Hi @tjorben-atomic-moss,

Edit: If you just want to know if the validation was successful, the best way is to react to the Events.eventButton action. It gets dispatched if the button validation was successful. You can find an example here. If you also want to get notified about failures, the following part is still true.

The Form Engine dispatches Commands.CorrectionMode.setValidationBarState unconditionally on every full validation. The “visible” property is only set if it was not successful. The following code should be what you want:

	const result = yield* take(
		(a: AnyAction): a is Action<FormEngineActions.FormEngineEventActions> =>
			FormEngineActions.command.match(a) && Commands.CorrectionMode.setValidationBarState.match(a.payload.engineEvent)
	);
	const success = !result.payload.engineEvent.payload.validationBar.visible;

You have to unwrap the dispatched actions from all engines, which is a bit unintuitive. And the FormEngineActions.FormEngineEventActions type lacks generic support, so it is typed as Action<any>, I will look into that.

Just as a note for future readers, please be aware that using engine command actions creates a pretty tight coupling to engine behavior, as the kind of command actions and their order might change with future versions.