I am trying to validate the inputs of a form, call a Dynamic Data service if the page is valid, and then change page if the service did not fail.

 My solution to this was to validate the page using Form.validate(), call the service, and then call the page transition.

This worked fine, but I when I tried to use Form.goToNextError() on an invalid response from Form.validate(), nothing happened. I have found a workaround but I am wondering; what is the expected functionality and use-case of Form.goToNextError()?

    CommentAdd your comment...

    1 answer


      This is partially not documented, and partially not documented well.

      Calling Form.validate() does NOT setup enough data structures for Form.goToNextError() to function – as you found.  The documentation for Form.validate() and Form.goToNextError() does not cover this.

      maestro.Form.$Pages.validate(false); however will setup enough of the internal data for Form.goToNextError() to do something.  maestro.Form.$Pages.validate(false); is not documented at all.

      You could replicate the functionality somewhat by checking the promise from Form.validate(), and if invalid finding the page with the invalid field, changing to that page, then using Scroll.scrollTo() to highlight the problem field.

      Form.validate(Form.getItemFromPath("data.textField"), data).then(
        function(validation) {
          if(validation.valid) {
            // valid
          } else {
            // not valid
            var myItem = Form.items[validation.errors[0]["id"]];
            var myParents = Util.parents(myItem, null, true);
            Form.goToPage(myParents[2].id, true, true);
            $timeout(function() {
              // Have to run validation again, as page-change clears it.
              Scroll.scrollTo(myItem.id, true, 50);
            }, 300);

      That code works – not really pretty or optimized however.

        CommentAdd your comment...