I have a requirement to use a button to perform a form wide validation prior to submit, and depending on the result, certain section will be shown. We want to show the error items messages like the "Submit" button. Is there a way to do it? 

I had a look on the Form.validate function, it seems to return a validate result in an object, but I want the error to be shown on the page, how can this be achieved?



Mike Chen

    CommentAdd your comment...

    1 answer


      Hi Mike,

      You can achieve this by validating the whole form with Form.validate and then assigning the result object back into the Form.validation object which controls the display of errors.

        Form.validation = result;
      1. Unknown User (strube)

        David, I want to do something similar, but not the same. I'm keen to know how this would work with sequential validation, where this function would be called mid-way through the form.

        Would it validate pages that haven't been displayed yet? (subsequent pages after the current page)

      2. Mike Chen

        correct me if I am wrong, but I think in Form.validate() you can pass in the node you want to validate against, so if you pass in the id of the page, then it will only validate that page. If you don't provide anything, then it will validate the whole form.

      3. David Moore

        Yes that is correct Mike.

      4. Unknown User (strube)

        ... and I suppose the "then" happens if the validation passes?

        In other words, can we control, if the validation passes, then do something else?

      5. Mike Chen

        This is how I do it

        Form.validate(data.content).then(function(result) {
        if ((result.valid)) {

        //do your valid route

        } else 

        //do the else route


      6. Mike Chen

        the result.valid will  tell you if validation was successful or not.

      CommentAdd your comment...