1

I am using the Validity plugin (http://validity.thatscaptaintoyou.com/) in my Ajax app. Per the documentation, since I am not using a form, I call it as follows:

// This is the validation function:
function validateForm() {

    // Start validation:
    $.validity.start();

    // Validator methods go here:

    for(key in fields) {
        var nextField = fields[key];
        console.log("validating: " + nextField.name);
        nextField.validateField();
    }

    // All of the validator methods have been called:
    // End the validation session:
    var result = $.validity.end();

    console.log("validity result: ");
    console.log(result);
    // Return whether it's okay to proceed with the Ajax:
    return result.valid;
}

the validateField() function in my field object calls Validity function on my inputs like require(), assert(), match(), etc... This works fine the first time it is called - invalid inputs get flagged correctly. However, when it gets called subsequently, all the validation tests pass no matter what. The result object is: Object {errors: 0, valid: true}.

Is there some Validity function I need to call in between calls to validity.start()? (besides calling validity.end())

  • Are you using a different output mode? To test, you can go to http://validity.thatscaptaintoyou.com/livetest/ For form code, if you write: And for Validation code: $("#box").require(); You can press the submit button several times and it correctly flags the input. The implementation is http://validity.thatscaptaintoyou.com/livetest/js/demo.js As you can see, this is basically the same approach as the Ajax code you wrote. – Wyatt Mar 21 '13 at 03:09

0 Answers0