I have a page built in ASP.NET MVC 4 that uses the jquery.validate.unobtrusive library for client-side validation. There is an input that must be in the range of numbers. However, this range can be dynamically changed based on user interactions with other parts of the form.
The default values ββare checked just fine, however, after updating the attribute, the data-rule-rangecheck and message are still started at the original values.
Here is the entry to load the start page:
<input id="amount" data-rule-range="[1,350]" data-msg-range="Please enter an amount between ${0} and ${1}">
Correctly this is confirmed by the message Please enter an amount between $1 and $350if a number greater than 350 is entered.
After the event is triggered elsewhere, it is updated data-rule-range, and the element looks like this:
<input id="amount" data-rule-range="[1,600]" data-msg-range="Please enter an amount between ${0} and ${1}">
At this point, if you enter 500 at the entrance, he will refuse to check with the same previous message, which says that it should be between 1 and 350 US dollars. I also tried removing the validator and unobtrusive image from the form and parsing it again without any luck.
$('form').removeData('validator');
$("form").removeData("unobtrusiveValidation");
$.validator.unobtrusive.parse("form");
Is there a clean way to change validation behavior based on dynamic input attributes?
source
share