I've been struggling with this for a couple of days now.  I'm building
pages with tables containing checkboxes.  Each row of the table
represents a grouping of checkboxes,  The rows are generated in a PHP
loop and have the format:

<tr><td><input type="checkbox" name="question[row_number]
[checkbox_number]" /></td></tr>

So a small table with 3 rows and 3 checkboxes would go:

[1][1], [1][2], [1][3]
[2][1], [2][2], [2][3]
[3][1], [3][2], [3][3]

I need to be able to validate each row of checkboxes as a single
entity, ie no particular checkboxes have to be checked, but at least 1
checkbox on each row must be.  The minlength function says that it can
do a group of checkboxes but I can't figure out how to get this to
work.

Most of my rules are built inline, with metadata in the classes of the
inputs I want to validate.  I don't think that would be possible for
the checkboxes though.  I'm trying the following code instead:

$(function ()
{
        var checkRows   = $('.checkRow');

        $('.cmsSurvey:first').validate ({debug:true});
        if (checkRows)
        {
                checkRows.each (function ()
                {
                        $(':checkbox', this).rules ('add',
                        {
                                required        : true,
                                minlength       : 1
                        });
                });
        }
});

Each tr in the table gets the class of checkrow.  I grab the rows,
iterate over them and for each one, try and add a rule.  This rule
doesn't work, however, and seems to cause every checkbox in the table
to become required.  If I set required to false, I can submit the form
with no checkboxed checked.

Reply via email to