I'm using the Jquery Validation plugin and have a series of inputs with the same name in an array, for example 5 inputs with name="name[]"
I want to have at least one of these required. Would anyone know how to do this? Thanks!
I'm using the Jquery Validation plugin and have a series of inputs with the same name in an array, for example 5 inputs with name="name[]"
I want to have at least one of these required. Would anyone know how to do this? Thanks!
You can state this more generally as "at least X inputs that match selector Y must be filled." (In your case, X is 1 and Y is "with a specific name.")
I addressed the general problem here:
jQuery Validate - require at least one field in a group to be filled
You can add a dependency callback to your "requires" rule. It lets you give a function for whether a field is required or not.
Make the first field required unless any of the other fields are filled in.
Do this by making it required, and setting the dependency callback to a function that loops through all the other fields and returns false if any of them has a value. See: http://docs.jquery.com/Plugins/Validation/Methods/required#required.28.C2.A0dependency-callback_.29