add a validation error to the current form if a form of a previous step became invalid #98
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This ensures that validation errors on previous steps are not ignored. Let's take this data object for a flow with three steps:
A user starts the flow, enters a title in step 1, submits the form, arrives at step 2. Now the dev decides to uncomment the lines above and deploys the code. The user submits the form for step 2 and arrives at step 3. The forms of step 1 and 2 are validated. Although the title given in step 1 now results in a validation error, this error message is not shown to the user and he could just finish the flow with (now) invalid data.
This PR fixes this by explicitly checking the forms of previous steps for errors when
$flow->isValid($form)
is called, and, in the above example, adds a generic error message when the user tries to submit the form for step 2: "The form for step 1 is invalid. Please go back and try to submit it again." Once the user does that, he will see the "Oh no!" validation error.Note: Validating the forms of previous steps is already done by the Form component when binding the data of previous steps. We'll just check if there are any errors.
In contrast, the 2nd commit allows to disable the revalidation of previous steps.