custom method to check if child div hasClass - jquery validate

TheDaemon

New Member
I have been fighting with a custom validation all day, I thought it was about time to ask for some help.What I have built is a select user interface similar to facebook when you add users to an event. I am trying to build a function that will return an error if none of the users are selected. The problem I am running into is that the parent div needs to be treated like a form element, but I can find any info on how to do that. Another thought came to me while i was making the JSfiddle. I store the User ID's in an array. Maybe the validation could check for an empty array? Im not sure how to do that either, or which way would be ideal..Here is a fiddle to play with:http://jsfiddle.net/7neCU/1/Here is what I have tried so far.\[code\] $.validator.addMethod('require-one-div', function (element) { if ($('#trainees').children('.each_user').hasClass('selected')) return true; }, "Please select at least 1 trainee");\[/code\]and the rules\[code\] rules: { trainees:{ 'require-one-div':true }, }\[/code\]I also gave the parent div \[code\]#trainees\[/code\] the name & id "trainees" and class of required.Thank you for any suggestions or ideas.
 
Back
Top