how i can validate dropdownlist with unobtrusive javascript ? As its validating textbox for required validator , but its not working for dropdownlist ?
Need to change unobtrusive js file for it ? or is there any other option to validate dropdownlist ?
i want to show errors when i checked form.validate() in my javascript .
Markup
<p>
<label for="ProductCategoryList">Product Categories</label>
<%= Html.DropDownList("ProductCategoryList", ViewData["ProductCategories"] as SelectList)%>
</p>
And the validation script
$.validator.addMethod("selectNone",
function (value, element) {
return this.optional(element) || element.selectedIndex != 0;
},
"Please select an option."
);
$(function () {
$("#form1").validate({
rules: {
ProductCategoryList: {
selectNone: true
}
},
messages: {
ProductCategoryList: {
selectNone: "This field is required"
}
}
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With