Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Why not use a custom validation method ? Something like this:</p> <p><strong>jQuery:</strong></p> <pre><code>// The custom validation method, returns FALSE (invalid) if there are // no checkboxes (with a .one_required class) checked $.validator.addMethod("one_required", function() { return $("#myform").find(".one_required:checked").length &gt; 0; }, 'Please select at least one vehicle.'); $("#myform").validate({ // Use the built-in errorPlacement function to place the error message // outside the table holding the checkboxes if they are the ones that // didn't validate, otherwise use the default placement. errorPlacement: function(error, element) { if ($(element).hasClass("one_required")) { error.insertAfter($(element).closest("table")); } else { error.insertAfter(element); } } }); </code></pre> <p><strong>HTML:</strong> </p> <pre><code>&lt;form id="myform"&gt; &lt;!-- table, rows, etc --&gt; &lt;td align="center"&gt;&lt;input type="checkbox" class="one_required" name="selectItems[]" value="NA245852" /&gt;&lt;/td&gt; &lt;td&gt;NA245852&lt;/td&gt; &lt;!-- more rows, end table, etc --&gt; &lt;br/&gt; &lt;input type="submit" value="Go, baby !"&gt; &lt;/form&gt; </code></pre> <p>Since the jQuery Validate plugin can also validate an element if the method name is present as a <code>class</code>, simply output the <code>.one_required</code> class on all checkboxes.</p> <p>See a <a href="http://jsfiddle.net/8L5C2/" rel="noreferrer">working demo on JSFiddle</a> with multiple checkboxes.</p> <p><strong>EDIT:</strong></p> <p><a href="http://jsfiddle.net/Z8hWg/35/" rel="noreferrer">Here</a>'s your own code with the above solution implemented.</p> <p>Hope this helps !</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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