If I have a required field on my form within my MVC3 page, and try submitting the form, the validation fires and the input control is given a light-red background color (fill) and it also shows a validation message. If I type in the input control, it will detect the value and remove both the coloring and validation method. This is how it should work.
In my case, I have mailing address fields, most of them required. I have an option on my site to select an address in a drop down list. When an address is selected by the user, all the address fields filled in using client side javascript. However, when I do this, my validation message and color aren't going away. So I need to somehow force the validation check.
How is this done?
Thanks in advance.
If I have a required field on my form within my MVC3 page, and try submitting the form, the validation fires and the input control is given a light-red background color (fill) and it also shows a validation message. If I type in the input control, it will detect the value and remove both the coloring and validation method. This is how it should work.
In my case, I have mailing address fields, most of them required. I have an option on my site to select an address in a drop down list. When an address is selected by the user, all the address fields filled in using client side javascript. However, when I do this, my validation message and color aren't going away. So I need to somehow force the validation check.
How is this done?
Thanks in advance.
Share Improve this question asked May 17, 2013 at 17:01 Jeff ReddyJeff Reddy 5,67010 gold badges58 silver badges91 bronze badges 1- possible duplicate of How to manually trigger validation with jQuery validate? – Jason Berkan Commented May 17, 2013 at 17:02
1 Answer
Reset to default 3The reason validation fires for your inputs is because they hook up to your change, focus, blue, keypress, etc events. For a scenario of where you fill the fields in with script you'll need to specifically call each element that had it's value populated. The reason for this is because the change event will not be fired. Just select the element with jQuery and call the valid method on it for jQuery Validate. The valid function will force validation on the element when called.
jQuery Validate Valid Documentation
Example
$("#mySelect").change(function() {
$("#myElement1").val("Some Value");
$("#myElement1").valid();
});
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745400907a4626095.html
评论列表(0条)