I have some <select>
inputs using the chosen plugin that I want to validate as "required" on the client side. Since "chosen" hides the actual select element and creates a widget with divs and spans, native HTML5 validation doesn't seem to work properly. The form won't submit (which is good), but the error message is not shown, so the user has no idea what's wrong (which is not good).
我已经求助于jQuery验证插件(无论如何我都计划最终使用它),但到目前为止还没有任何收获.这是我的test case分:
<form>
<label>Name: <input name="test1" required></label>
<label>Favorite Color:
<select name="test2" required>
<option value=""></option>
<option value="red">Red</option>
<option value="blue">Blue</option>
<option value="green">Green</option>
</select>
</label>
<input type="submit">
</form>
$(document).ready(function(){
$('select').chosen();
$('form').validate();
});
这是在不验证或显示错误消息的情况下,以空值让select
通过.当我注释掉chosen()
行时,效果很好.
How can I validate chosen()
inputs with the jQuery validation plugin, and show the error message for invalid ones?