javascript - JQuery Validation Weird Behavior on Validating Dropdown List -
i'm using jquery validation validate dropdown list follows:
here javascript part:
$.ready(function(){ $.validator.addmethod("dropdown", function (value, element) { return validatedropdowns(this, value, element); }); $('#form1').validate({ onsubmit: false, focusinvalid: true, highlight: function (element, errorclass, validclass) { $(element).toggleclass('invalid'); $(element.form).find("label[for=" + element.id + "]").toggleclass(errorclass); }, unhighlight: function (element, errorclass, validclass) { $(element).toggleclass('invalid'); $(element.form).find("label[for=" + element.id + "]").toggleclass(errorclass); } }); }); function validatedropdowns(objcontext, value, element) { return objcontext.optional(element) || value != "-1"; }
and here markup part:
<asp:dropdownlist runat="server" id="cmbgender" clientidmode="static" meta:resourcekey="cmbgenderresource1"> <asp:listitem selected="true" value="-1" text="please select gender" meta:resourcekey="listitemresource1"></asp:listitem> <asp:listitem value="1" text="male" meta:resourcekey="listitemresource2"></asp:listitem> <asp:listitem value="2" text="female" meta:resourcekey="listitemresource3"></asp:listitem> </asp:dropdownlist>
i have submit button , on click validate form return $("#form1").valid();
now works fine in chrome , firefox in ie9 weird behavior; dropdown works fine before validation , after validating it. when try open dropdown close immediately.
add onclick: false
in validation option:
e.g.
$(".selector").validate({ onclick: false })
this worked me.
Comments
Post a Comment