jQuery Validate doesn't remove error if value is auto-inputted via JavaScript -


my html looks this:

<form id="mainform" method="post">     <input type="text" class="required" name="receiver" />     <span id="clickme">click me</span>     <input type="submit"> </form> 

and javascript follows:

$(document).ready(function () {     $("#clickme").click(function() {         $("input[name=receiver]").val("clicked");     });     $("#mainform").validate({         submithandler: function (form) {             alert("success!");             return false;         }     }); }); 

fiddle: http://jsfiddle.net/y9rft/2/

if submit leaving input empty, error appears.

if click 'click me' span, input auto-filled, error remains until submit form. if type instead, error disappears instantly.

is there way emulate user input error disappears on click?

simply use the built-in .valid() method force immediate validation test of form.

$("#clickme").click(function () {     $("input[name=receiver]").val("clicked");     $("#mainform").valid();  // <<-- add line force test }); 

demo: http://jsfiddle.net/y9rft/8/


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -