Reputation: 717
Im having difficulty removing the error from the area assigned by the errorPlacement once field is validated. Any help is really appreciated!
$('document').ready(function(){
$('form').validate({
rules: {
a: {required:true, minlength:2}
},
messages: {
a: {required: "enter your name!"}
},
errorPlacement: function(error, element) {
if(element.attr('name') == 'a'){
error.appendTo($('#restErrorDate'));
}
},
success: function(error){
},
debug:true
});
$('#a').blur(function(){
$("form").validate().element("#a");
});
});
Here is the html:
<div>
<form action="#" id='commentForm'>
<input type="text" name="a" id="a">
</form>
</div>
<div id="restErrorDate" class="restErrorDate" style="border:1px solid blue;"></div>
and here is the jsfiddle:
http://jsfiddle.net/mmw562/Evxd9/
Upvotes: 1
Views: 1101
Reputation: 102745
Instead of appending (which will keep adding more), just overwrite all the existing HTML:
errorPlacement: function(error, element) {
if(element.attr('name') == 'a'){
// error.appendTo($('#restErrorDate'));
$('#restErrorDate').html(error);
}
},
Demo: http://jsfiddle.net/Evxd9/2/
Upvotes: 3