Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a validation error to the current form if a form of a previous step became invalid #98

Merged
merged 9 commits into from
Dec 17, 2013

Conversation

craue
Copy link
Owner

@craue craue commented Nov 9, 2013

This ensures that validation errors on previous steps are not ignored. Let's take this data object for a flow with three steps:

/**
 * @Assert\Callback(methods={"isTitleValid"}, groups={"flow_createTopic_step1"})
 */
class Topic {

    public $title;

    public function isTitleValid(ExecutionContextInterface $context) {
        // TODO: I really have to check this soon.
//      if ($this->isThereSomethingWrongWithTheTitle()) {
//          $context->addViolation('Oh no!');
//      }
    }

}

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.

@craue craue mentioned this pull request Dec 16, 2013
31 tasks
craue added a commit that referenced this pull request Dec 17, 2013
add a validation error to the current form if a form of a previous step became invalid
@craue craue merged commit cf7b778 into master Dec 17, 2013
@craue craue deleted the revalidate-previous-steps branch December 17, 2013 09:47
craue added a commit that referenced this pull request Jan 7, 2014
craue added a commit that referenced this pull request Mar 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant