Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Form Questions /

Validate - Limit # of Checkboxes or Customize Name within Input


Reply


2 Posts   918 Views

Avatar
socks

Community Member, 190 Posts

22 August 2011 at 6:27pm

I'm trying jQuery Validate to limit the # of checkboxes a user can choose in my form (MultiForm module). To do that, the set of checkboxes need to have the same name=" " within the input.

ie.

<input name="tech" id="ebio" type="checkbox" value="" />
<input name="tech" id="mna" type="checkbox" value="" />

If I use something like $dataFieldByName(Bla) to generate the input field in the template, it doesn't allow me to specify the name part of the input that I know of.

If I write out the input manually, the checkbox state isn't being saved when I go to another page/step of the form and come back.

Any Suggestions?

Avatar
Devlin

Community Member, 217 Posts

22 August 2011 at 8:59pm

http://api.silverstripe.org/trunk/forms/fields-basic/CheckboxSetField.html

To limit the user input with jQuery, simply count all checked children of .checkboxsetfield. Something like:

var count = $("ul.checkboxsetfield input:checked").length;

http://api.jquery.com/checked-selector/