brutusin / json-forms

JSON Schema to HTML form generator, supporting dynamic subschemas (on the fly resolution). Extensible and customizable library with zero dependencies. Bootstrap add-ons provided
http://brutusin.org/json-forms
Apache License 2.0
607 stars 168 forks source link

onValidationError alert #58

Closed vincentmorneau closed 7 years ago

vincentmorneau commented 7 years ago

I believe bf.validate() https://github.com/brutusin/json-forms/blob/master/src/js/brutusin-json-forms.js#L103 could return a JSON object with the message instead of forcing an alert.

Example:

var validation = bf.validate();
if (!validation.success)
   console.log(validation.message); // then we can choose what to do with the message

What do you think?

idelvall commented 7 years ago

Hi, this is just the default implementation. You can override the handler by setting your own

BrutusinForms.onValidationError = function (element, message) {
        element.focus();
        if (!element.className.includes(" error")) {
            element.className += " error";
        }
        alert(message);
    };
vincentmorneau commented 7 years ago

Sounds good! Closing this.