You are viewing limited content. For full access, please sign in.

Question

Question

Checkboxes to Require At Least 3 Selections

asked on September 16, 2021

I have a form which includes a checkbox field with 12 possible options.

The department who requested this form has a requirement that at least 3 of the options are marked.

I've been thinking about how this could operate with Javascript and I'm coming up blank.

Does anyone have any experience doing something similar to this that could share some code?

Thank you.

0 0

Answer

SELECTED ANSWER
replied on September 16, 2021 Show version history

Parsley to the rescue!

$(document).ready(function () {
  $('.myCheckboxes input').attr('data-parsley-mincheck','3');
});

Forms already imports the Parsley validation library, so it's literally that simple.

Just set the 'data-parsley-mincheck' value and you're done as long as your field is required.

1 0
replied on September 17, 2021

There is a "mincheck" value!?  I must have done 10 different Google searches (regarding parsley) to try to find that and came up short.  Don't know how I missed it...

Thank you so much @████████, you're always great to teach me something new.

It worked perfectly by the way.

0 0
replied on September 17, 2021

Yea, there's a lot to sift through in their documentation. More than once I've built a custom validator only to later find out they have a built-in option lol.

1 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.