开发者

Jquery validate - how to require specific options from drop down menu to be selected before validation

开发者 https://www.devze.com 2023-02-26 06:20 出处:网络
If I require one specific option frpm drop down menu to be select开发者_如何学JAVAed before validation of some field, I do like this:

If I require one specific option frpm drop down menu to be select开发者_如何学JAVAed before validation of some field, I do like this:

required: "#employmentStatusSTUDENT:selected",

How can I make this requirement to be applied also in case other option is selected?

Something like:

required: "#employmentStatusSTUDENT:selected||#employmentStatusEMPLOYEED:selected",

doesn't work of course...


I am going to guess you could do this similar to how a checkbox or radio is done. Instead of making an option required, set the required to the select node. then give the list of required options a class. I used 'myRequiredOptions:selected'.

required: "#mySelect > option.myRequiredOptions:selected"


Use anonymous function

required: function(){return $("#employmentStatusSTUDENT:selected")||$("#employmentStatusEMPLOYEED:selected");}
0

精彩评论

暂无评论...
验证码 换一张
取 消