rickharrison / validate.js

Lightweight JavaScript form validation library inspired by CodeIgniter.
http://rickharrison.github.io/validate.js
Other
2.56k stars 406 forks source link

Form validation is bypassed if any exceptions within custom callback #217

Open christoferd opened 5 years ago

christoferd commented 5 years ago

Form submits with errors after a validation.

Issue: For some reason this library does not perform validation correctly whenever classes are added to the form input elements. Update: I have found out that if there are any exceptions thrown from within the custom callback function, the form will submit and bypass the validation!

Further issue:

Scenario: I have setup validation options with the second argument, the callback function.

What makes this very difficult to solve is that the validator ignores the exception, does not report to console.log and continues to redirect the user to the next page. 👎

What I suggest to improve this, and help people avoid this issue: In the example documentation, update to something like this:

    // Validation Configuration
    var validator = new FormValidator('myFormId', [
        // ...
        // validation settings
        // ...
    ], function (errors, event) {
        try {
            // Custom code goes here
        } catch (ex) {
            // This is displayed if any major errors occur in the custom code
            console.error('** ERROR IN FORM VALIDATION CALLBACK FUNCTION **');
            console.error(ex);
        }
    });