I've been using the jquery validate for a while now and have just recently started working with the remote option.
When I use remote validation with an input element, it works great (email, phone #, etc). I'm now trying to have it work with a multiple select element. I don't understand when the validation via remote gets fired. The first time I make a selection in the element, it fires off the remote and it does what it's supposed to do. Then when I Ctrl-Click, Shift-Click, or single click elsewhere, it doesn't always perform the validation and call the remote ajax method.
<!-- HTML snippet -->
<form id="edit_user_form" action="" method="post">
<input type="text" name="username" id="edituser_username"/><br/>
<select name="roles" id="edituser_roles" size="5" multiple="multiple"></select>
</form>
// jquery snippet
$('#edit_user_form').validate({
rules: {
username: { required: true },
roles: {
required: true,
remote: {
type: "POST",
url: "/AdminJson/CheckRolesAllowed",
dataType: "json",
data: {
roles: function () { return $("#edituser_roles").val(); }
}
}
}
},
I also tried setting onfocusout validate option to true to force the validation when the blur event occurred. No change.
I went so far as to hook into both the blur and change event handlers and try element as seen below, but that didn't work either.
$("#edituser_roles").change(function () {
$("#edit_user_form").validate().element("#edituser_roles");
});
$("#edituser_roles").blur(function () {
$("#edit_user_form").validate().element("#edituser_roles");
});
My question is this: when does the remote validation get called for a multiple select element? Can I force it to validate on both blur and whenever a change is made in the multi-select?
Thanks in advance