ddarren / jQuery-Live-Form-Validation-For-Twitter-Bootstrap

This is an adaptation of the jQuery Live Form Validation found at http://www.geektantra.com/2009/09/jquery-live-form-validation/ for Twitter Boostrap. The modified script will allow for live form validation using the Twitter Bootstrap HTML pattern for forms.
114 stars 21 forks source link

Form with invalid field followed by valid file field does not mark any fields as erroneous on submit #3

Closed cheshire137 closed 12 years ago

cheshire137 commented 12 years ago

I had a form with two fields, both validated. The first field required a value, and defaulted to having no value. The second field was type=file and did not require a value. Without touching either of the fields, I hit the submit button for the form. The first field was not marked as erroneous (unexpected behavior), nor was the second field (expected behavior). I think I fixed the problem. I changed this:

if (validate_field('#' + SelfID)) {

    jQuery('.' + options['error_message_class']).remove();
    jQuery('.' + options['error_container_class']).removeClass('error');

    return true;
}
else 
    return false;

To this:

var fieldSel = '#' + SelfID;
if (validate_field(fieldSel)) {
    jQuery(fieldSel + ' + .' + options['error_message_class']).remove();
    jQuery(fieldSel).closest('.' + options['error_container_class'])
            .removeClass('error');
    return true;
} else {
    return false;
}

You were removing all error messages and taking the 'error' class off of all control-group div's, instead of just those associated with the field that's valid.