Joomla 5 Notice

We are pleased to announce that as of January 29, 2024, all of our Joomla extensions are compatible with Joomla 5.

For all who are still updateing from Joomla 3 to Joomla 4: Joomla 4 Migration instructions are available here:

There is now a separate Documentation for Visforms for Joomla 4 and for Visforms for Joomla 5!

Forum

Visforms Subscription user can ask questions in our forum. Please log in with the relevant user first.
Everybody can access the forum for reading.

Please only ask 1 question per topic.

How to allow only one checkbox checked of a checkboxgroup?

More
6 years 3 days ago - 6 years 3 days ago #5459 by jjs
Hello Aicha,

how do i allow only one checkbox to be checked by visitor?
The checkboxes are both (yes and No) unchecked.

When i use the minimum and maximum value and set it to 1, it does not seem to work. At least i expect if one checkbox is checked and then for example the other one is checked, the first one should be automatically be unchecked. (similair like Radio Buttons behaviour, but none may be pre checked while entering the form the first time.)

What do i need to set here to have it work correctly? Or is it a bug?

Thanks very much.
Jerry
Last edit: 6 years 3 days ago by jjs.

More
6 years 3 days ago #5461 by Administrator AV
Replied by Administrator AV on topic How to allow only one checkbox checked of a checkboxgroup?
Hi Jerry,

maybe this documentation article can help you to understand better how the validation works.
www.vi-solutions.de/en/documentations/vi...validate-user-inputs

If you want to enforce, that a user must make an input (or in your case, check a checbox) you have to make the field required. If the field is not required an empty value (nothing checked) is a valid user input.

The min/max length validation only kicks in, when the user makes an input. So if you set the minimum value and the maximum value to yes, Visforms will validate that only one checkbox is checked. If more than one checkbox is checked, it will prevent the user from submitting the form and will display an error message after the user has hit the "Submit" button.

Checkbox-groups do not behave like radio buttons, because it is an intirinsic behavior of radio buttons, that only one option can be selected, and this is not an intrinsic behavior of a checkbox group. It is the browser, that automatically unchecks a radio button, if anonther otpion es selected, not Visforms and this behavior is not implemented for checkbox groups (in the browser).

So I think, there is no bug in Visforms. Set the required to yes, set minimum and maximum lenght to 1 and the form can only be submitted, if the user has check exactly one checkbox of the group. If they check none or more than one, an error message will be displayed on submit and they have to correct the input manullly.

Regards,
Aicha

:idea: I recommend you the new and up-to-date documentation for Joomla 4:
docs.joomla-5.visforms.vi-solutions.de/en/docs/
Most of this also applies retrospectively to Joomla 3.
Please only ask 1 question per topic :-).

:idea: Ich empfehle Dir die neue und aktuelle Dokumentation für Joomla 4:
docs.joomla-5.visforms.vi-solutions.de/docs/
Das meiste gilt rückwirkend auch für Joomla 3.
Bitte immer nur 1 Frage pro Thema stellen :-).

More
6 years 3 days ago #5462 by jjs
Hello Aicha,

great! thanks.
I had it required, but somehow i did not see it work correctly.
But indeed it does work, when both checkboxes are checked, a notification is popping up that only one can be checked.
Thanks a lot!

Moderators: Administrator AVAdministrator IV
Powered by Kunena Forum