user791187
user791187

Reputation: 717

jQuery validate errorPlacement removal

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

Answers (1)

No Results Found
No Results Found

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

Related Questions