Validating all checkboxes are checked in group

  • Posts: 2483
  • Karma: 86
  • Thank you received: 335

mihaela replied the topic: Validating all checkboxes are checked in group

Hello,

To make this work for your form, replace all instances of criteria with the Name of your checkbox group element.
Other than that, replace 4 with the number of checkboxes that you have in the checkbox group.

The code has to look like this:
function ff_yourcheckboxgroupname_validation(element, message)
{
var checkboxes = JQuery("[name=\"ff_nm_yourcheckboxgroupname[]\"]:checked");
if(checkboxes.length != number of ckeckboxes){
    return message;
}
return '';
} // ff_yourcheckboxgroupname_validation

Let me know whether you have managed to set this for your form.
If you have more questions, feel free to post on our forums.

Regards,

Mihaela
#228863
  • Posts: 271
  • Karma: 5
  • Thank you received: 3

uglyeoin replied the topic: Validating all checkboxes are checked in group

I'm having trouble with this. I think I might be adding it in the wrong place.

My checkbox group name is "Consent".
It has two checkboxes.

my code is
function ff_Consent_validation(element,message)
{
var checkboxes = JQuery("[name=\"ff_nm_Consent[]\"]:checked");
if(checkboxes.length != 2){
    return message;
}
return '';
} // ff_Consent_validation

I've tried it in the scripts panel for initialise and for submit.
I've tried it in the submit pieces panel, but that doesn't like JS.

Where should it go? Does I need ff_nm_ in my code above?

The form submits as normal.
#233921
  • Posts: 2483
  • Karma: 86
  • Thank you received: 335

mihaela replied the topic: Validating all checkboxes are checked in group

Hello,

Please try to use the following code instead of the one that you were using:
function ff_Consent_validation(element, message)
{   var checkboxes = JQuery("[name=\"ff_nm_Consent[]\"]:checked");
    if (checkboxes.length != 2) {
        if (message=='') message = "Please check all checkboxes.\n"
        ff_validationFocus(element.name);
        return message;
    } // if
    return '';
} // ff_Consent_validation

Go to Properties of the "Consent" element and scroll down. In the Validation section check the Required checkbox and set the validation Type to Custom. Then in the code area that appears, put the above suggested code.

Let me know whether it works for your form after you do the suggested change.

Regards,

Mihaela
#233998
  • Posts: 271
  • Karma: 5
  • Thank you received: 3

uglyeoin replied the topic: Validating all checkboxes are checked in group

That worked, thank you!
#234006
  • Posts: 2483
  • Karma: 86
  • Thank you received: 335

mihaela replied the topic: Validating all checkboxes are checked in group

Great! I'm glad that it did.
#234008
Moderators: ForumSupporttomeperica
Time to create page: 0.079 seconds

New Icon Packs Category!

Crosstec is now offering icon packs.

If you are a paying subscriber, icon packs are automatically added to your account.

Check out our icon packs page!

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

Summer Sale!

50% discount on all of our extension subscription plans, templates and icon packs!

Get Your Subscription Here

News and Updates

Get informed about new downloads, updates and more in our News and Updates newsletter.

All Extensions Subscription

Get 1 year access to all of our current and future products and 1 year of professional support -- 99 for just 49! (Summer Sale)

No support per domain or website installation limits! Includes all of our current and future Joomla!® extensions, Joomla!® templates for the duration of your membership. This means, by purchasing an All Extensions Subscription you'll have it all covered!

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

Community Reward

Help us to create new extensions and plugins! With only $5 you help us a lot and get unlimited download access to all of our products, professional support and even more. Get your reward now!

Read More Here