jQuery unobstrusive validation returning valid when it is not
I have a form that has a required input, but jQuery is saying that the field is valid when开发者_开发技巧 it is not. It is strange, because the by the HTML it looks like it has value.
This is the output of three commands in the Chrome console with the textbox totally empty:
// First I ensure that the selector is correct. But I can see that it has value,
// when it is actually empty.
$('#form_0 input[name=Name]')[0].outerHTML
"<input data-val="true" data-val-length="The field Customer name must be a string with a minimum length of 3 and a maximum length of 20." data-val-length-max="20" data-val-length-min="3" data-val-required="The Customer name field is required." id="Name" name="Name" type="text" value=" Customer 0 " class="valid">"
// jQuery confirms that the field is empty
$('#form_0 input[name=Name]').val()
""
// but jQuery say that the control is valid :?
$('#form_0 input[name=Name]').valid()
1
The form and the inputs have been created dynamically with jQuery.
What could be the problem?
Thanks.
$.validator.unobtrusive.parse('#form_0');
I didn't know I have to call it again when I add inputs dynamically. I guess I have to read more documentation and less examples :P
精彩评论