Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>For this, you're pretty much going to have to create your own validation rule, but the rule you need is pretty simple. All members of that class will validate if there exists any member of that class with a value other than the default. Thus, you use the class selector, then filter further by the value not-equals selector, and check if the result contains anything.</p> <pre><code> jQuery.validator.addMethod( "groupSelect", function (value, element, isRunning) { return $('.groupSelectClass[value!="defaultSelectValue"]').length &gt; 0; }, "At least one must be selected."); </code></pre> <p>then just apply the <code>groupSelect</code> rule (the one written there) to the <code>groupSelectClass</code> class (which you make sure is added to all of your selectors on generation) and ensure that whatever you have in place of <code>defaultSelectValue</code> is actually the default value for the selectors. Note that this all needs to be set up before the base <code>validate</code> call, not after.</p> <p>Edit:</p> <p>Further explanation: the above block of code defines a validation rule by the name of <code>groupSelect</code> (or whatever you put there). As written, the <code>groupSelect</code> rule returns valid if and only if at least one of the nodes with the class "groupSelectClass" has some value other than "defaultSelectValue". If you make sure that everything with the class "groupSelectClass" is a select box with a default value of "defaultSelectValue", then this rule will return valid if and only if at least one of those select boxes has been set. If you then apply this rule to the "groupSelect" class using the <code>jQuery.validator.addClassRules</code> function, it will cause all of those select boxes to have that as a validation requirement, and display "At least one must be selected." on validation failure. <a href="http://docs.jquery.com/Plugins/Validation/Validator/addClassRules" rel="nofollow">http://docs.jquery.com/Plugins/Validation/Validator/addClassRules</a> should give you enough understanding of how to use the addClassRules function. Indeed, I'd recommend you read up on the stuff in that site in general, particularly the validation plugin information, if you're going to be doing much with it.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload