Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validation of a checkbox group. #40

Closed
frphilippe opened this issue Mar 5, 2019 · 13 comments
Closed

validation of a checkbox group. #40

frphilippe opened this issue Mar 5, 2019 · 13 comments

Comments

@frphilippe
Copy link

Bonjour,
I would like to validate a checkbox group with the latest version of bouncer.js 1.4.3 as the following CodePen:
https://codepen.io/anon/pen/KENaor
There must be at least one or more boxes checked but not necessarily all with a single error message.
Is it possible?
In what way.
Thank you for your reply.

@cferdinandi
Copy link
Owner

Possible duplicate? #17

Let me know if its not and I'll reopen.

@frphilippe
Copy link
Author

Bonjour,
I was aware of this conversation before contacting you but the operation I want will work with version 1.2.4.
https://codepen.io/anon/pen/KENaor.
But with the latest version 1.4.2 for a group of checkboxes that have the same attribute name there is an error message by Checkbox and all checkboxes in the group must be validated.
https://codepen.io/anon/pen/NJdWJz
Is it possible to find the operation of checkbox group validation (same attribute name) of version 1.2.4 with version 1.4.2?
Thank you.

@cferdinandi
Copy link
Owner

Apologies, but I'm not 100% sure I understand the desired behavior. Can you clarify?

@cferdinandi cferdinandi reopened this Mar 6, 2019
@frphilippe
Copy link
Author

I have a group of 12 checkboxes with the same attributename="Cours[]".
I would like to be able to validate the entire group if one or more checkboxes are selected.
If no checkbox is selected, only one error message will be required.
Which corresponds to the operation of the version 1.2.4.
Example: https://codepen.io/anon/pen/KENaor.

But we can not find this operation with the latest version 1.4.2
Example: https://codepen.io/anon/pen/NJdWJz. Checkbox validations are independent with an error message by checkbox.

Is it possible to find this operation with the version 1.4.2?
Thank you.

@robertodevivo
Copy link

This is exactly the issue i'm having using 1.4.3. Checkboxes that are part of the same checkbox group (i.e. they have the same value in the name attribute) are validated separately and not as a whole in this version of Bouncer.

Desired behaviour is that checkboxes with the same name attribute are treated as a group. This means that if a single checkbox is ticked within this group it will be valid as the requirement is met.

@cferdinandi
Copy link
Owner

Digging into this a little bit more, that's not consistent with how browsers treat checkboxes natively or what the expectation for checkboxes are.

A more robust form validator might better fit your needs around this.

@iamkeir
Copy link

iamkeir commented Aug 7, 2019

Just for future reference, for anyone struggling with this, you can make Bouncer work to validate a group of checkboxes where at least one must be checked:
https://codepen.io/iamkeir/pen/jgzOJr?editors=1010

The downside is you cannot use the required attribute, as we need to suppress the individual required validation. But, semantically, that is correct. We need a checkbox-group validation added to the HTML5 Validation API...

@cferdinandi I'd definitely welcome if you think this could be done more simply :)

@iamkeir
Copy link

iamkeir commented Aug 7, 2019

That said, the above starts outputting multiple error messages if you assign values to the checkboxes... which seems odd: https://codepen.io/iamkeir/pen/wVmKyV?editors=1010

Possible bug? Related to #17?

@iamkeir
Copy link

iamkeir commented Aug 12, 2019

Ref: #47

@xini
Copy link

xini commented May 1, 2020

I agree. A checkbox group with the same name attribute should be validated as a whole.
I think the multiple messages are related to the changes in #17 which includes the field value in the id in b450b24#diff-0825e4e8b268ffd0956559ebd7130bd7R407.
@iamkeir Have you found a work-around for this in the meantime?

@iamkeir
Copy link

iamkeir commented May 1, 2020

@xini I can't recall to be honest - I think I may have eventually used an alternative library such as ParsleyJS.

@xini
Copy link

xini commented May 2, 2020

@xini I can't recall to be honest - I think I may have eventually used an alternative library such as ParsleyJS.

Thanks. Yeah. I just really don't want to use jQuery...

@croxton
Copy link

croxton commented May 31, 2022

In case anyone runs across this, here's one way to validate a set of checkboxes:
https://codepen.io/croxton/pen/wvymNry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants