<select name="purchasableId" id="multiSelect" class="metre" multiple='multiple' required> <option disabled selected value='abc'>abc</option> <option value='xyz'>xyz</option></select>
这个给定的示例向我展示了一个带有可选验证js的必需警报,因为它处于禁用状态。 我希望如果在选择下拉列表中选择了任何选项,则不应在选择后显示所需的验证,无论在何处禁用都无所谓。
$("#multiSelect").validate({
ignore:"option:selected,disabled"
});
答案 0 :(得分:0)
您可以尝试通过这种方式进行操作:
//Use form id
$("#form").validate({
ignore: ".no-validate"
})
然后将类添加到您的选择中:
<select name="purchasableId" id="multiSelect" class="metre no-validate" multiple='multiple' required> <option disabled selected value='abc'>abc</option>
<option value='xyz'>xyz</option>
</select>
答案 1 :(得分:0)
通过添加规则获得解决方案
$( "#selector_id" ).rules( "add", {
required: function() {
var opion_selected_required =true; //if selected option not found fire validation required
$('#selector_id option').each(function() {
if($(this).is(':selected'))
{
opion_selected_required = false; //if selected option found do not fire validation required (where option disabled or enabled no matter)
}
});
return opion_selected_required;
}
});