gitana / alpaca

Alpaca provides the easiest way to generate interactive HTML5 forms for web and mobile applications. It uses JSON Schema and simple Handlebars templates to generate great looking, dynamic user interfaces on top of Twitter Bootstrap, jQuery UI, jQuery Mobile and HTML5.
http://www.alpacajs.org
Other
1.29k stars 371 forks source link

How to add errors to a field after a server validation? #598

Open punto- opened 6 years ago

punto- commented 6 years ago

Hi.

I have a form that is validated locally, but after it's submitted to the server it might return with some errors. I can't put the code in a custom validator function for a field because I need to send the entire form to the server (after local validation) to get the response. Is there a way to add errors to the form from outside of a validator callback? I see in the code that the errors are added as _this.validation["custom"], but I can't find what makes the errors show up afterwards?

Thanks!

punto- commented 6 years ago

As an update, I found the "displayMessage" method, but it doesn't show up as an error with the red text, regardless of what parameters I pass, is this the right one? thanks

WhileTrueEndWhile commented 6 years ago

Hi, first of all, I would like to draw your attention to the issues which are very similar to this one:

How to use a validator can be found in the issues. Since you mentioned displayMessage, I take you may have seen some of them already. As you can test with the following configuration, the message from displayMessage is no longer visible after the next validation (perhaps this information could help you with your problem):

{
    ...
    "postRender": function (topControl) {
        setTimeout(function () {
            topControl.displayMessage("Hello World. (Validate to hide me)");
        }, 250);
    }
    ...
}