I have a form with ASP MVC3, and the input
fields are validated with jQuery validate plugin v1.8 (default jQuery validation with MVC3). This is working perfectly, but the problem is when I insert a new field to validate using the after
or append
function.
If I have this HTML:
<label for="name">Name: </label>
<input class="text-files" data-val="true" data-val-required="Name missing" id="name" name="name" type="text" value="">
<span class="field-validation-error" data-valmsg-for="name" data-valmsg-replace="true"></span>
It works OK, but if I insert it with after
or insert
function, it doesn't work:
$(window).load(function () {
$('#addName').click(function (event) {
event.preventDefault();
var $newdiv = $('<label for="name">Name: </label><input class="text-files" data-val="true" data-val-required="Name missing" id="name" name="name" type="text" value=""><span class="field-validation-error" data-valmsg-for="name" data-valmsg-replace="true"></span>');
$('.names').append($newdiv);
});
});