views:

25

answers:

1

required( dependency-expression )

They give an example of required: "#other:checked" but I want my field to be required if the #other field is either :checked or :filled (I don't know whether it will be a checkbox, radio button, or textbox beforehand). How would I do this?

+2  A: 

Since it checks length of the jquery element matching this selector, this should work:

required: "#other:checked, #other:filled"

This is the code that actually uses that string:

return !!$(param, element.form).length;

An easier way to think about it: if $(yourString, yourForm).length > 0, it will be a required field.

Nick Craver
That's kind of weird. Why do they use double negation instead of `> 0`? Is it faster?
Mark
@Mark - Not sure, style choice I guess, might be faster in some browsers/tracing engines.
Nick Craver