This is related to this question: Validation for selecting a minimum and maximum
So I have two fields one for minim and one for maxim that the user must enter. I need to have a validation on both field that they are correct minim < maxim.
I have the following code
$.validator.addMethod('lessthan', function (value, element, params) {
var greatElement, validator, less, greatText, isEqualValid, great;
greatElement = $(params[0]);
// This code does not work
//validator = $( greatElement[0].form ).validate();
//validator.element(greatElement);
// This code does not work
greatElement.valid();
// validate the current value
// missing for brevety
});
$.validator.unobtrusive.adapters.add('lessthan', ['compareto', 'isequalvalid'], function (options) {
var element = $(options.form).find('input[name=' + options.params['compareto'] + ']')[0];
options.rules['lessthan'] = [element, options.params['isequalvalid']];
options.messages['lessthan'] = options.message;
});
However when I am trying to validate the other field for the current field even though the aria-invalid is not true the input-validation-error class is not removed.
How can I trigger the validation for the other field inside the validation function?
UPDATE I should mention that the case I need to fix is when validation is executed when I change one of the fields (keyup or lostfocus).
Example: I have min 2 and max 5. I change the min to 23 both fields become invalid and have the error class associated with them I change the min to 3 only the max field becomes valid. The min field remain invalid even though the validation function returns that is valid.