Score:0

Check minimum checked Checkboxes

kh flag

i am new to the drupal world.

I have created a web form, there are several checkboxes there. like:

[1]
[2]
[3]
[4]

I would like to check whether at least X of the checkboxes are selected before sending. I have no idea how to set it up.

I would be very happy to hear from you.

Thanks very much

Score:0
cn flag

If you really only need one item to be checked, setting the field as required would be the only thing you need to do. When you are in build mode of the webform and you click the element that needs this setting, there is a section called "FORM VALIDATION." If you click to expand this, there is a checkbox to make it required.

Update: the Webform documentation shows how to add custom validation to a Webform.

kh flag
Many thanks for your response. This would be possible with only one checkbox, but unfortunately not if there should be 2 or more.
shelane avatar
cn flag
Ah, I see. I read this question wrong. So, I think you’ll have to do custom JavaScript validation to verify that there is at least one value from one of the checkboxes. Webform has great documentation including the [cookbook for handlers](https://www.drupal.org/docs/8/modules/webform/webform-cookbook/how-to-add-custom-validation-to-a-webform-element) for just such a purpose.
kh flag
Thanks. I'll try it. don't have that much programming knowledge yet
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.