TOPIC:

How to make multi fields required if 1 check box is checked? 3 months 1 week ago #244615

  • Topic Author
  • ahmeds2
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 49
  • Thanks: 0
Dear Sir/Madam,

Could you help me?

How to make multi fields required if 1 check box is checked (and the viceversa)?

Best Regards,
Ahmed Al-Wareeth

Please Log in or Create an account to join the conversation.

How to make multi fields required if 1 check box is checked? 3 months 1 week ago #244632

  • TheMuffinMan's Avatar
  • TheMuffinMan
  • Offline
  • Developer
  • Developer
  • Posts: 10064
  • Karma: 167
  • Thanks: 803
Hi,

do you need to make a completely different element mandatory or other checkboxes of the same checkbox group element?

Regards,
Markus

Please Log in or Create an account to join the conversation.

How to make multi fields required if 1 check box is checked? 3 months 1 week ago #244650

  • Topic Author
  • ahmeds2
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 49
  • Thanks: 0
Hi,

I need to make completely different elements mandatory.

For example:
I have a checkbox and three textboxs Fields, and if the check box is checked I want to make 3 textboxs are mandatory (required). and if checkbox is unchecked the textboxs are not required.

Best Regards,
Ahmed

Please Log in or Create an account to join the conversation.

Last edit: Post by ahmeds2.

How to make multi fields required if 1 check box is checked? 3 months 1 week ago #244671

  • TheMuffinMan's Avatar
  • TheMuffinMan
  • Offline
  • Developer
  • Developer
  • Posts: 10064
  • Karma: 167
  • Thanks: 803
Hi,

in principle, I would use a custom action to check what items have selected.
Then on the affected elements I would apply a custom validation that only triggers when the conditions for the checkbox group are matched.

So let's say you have 1 checkbox group called A and 1 element called B that should fire if one of A' elements has been selected, then I would first add this to B => validation => click custom => click create code framework:
ff_B_validation(element, message){

     let A = 'NAME-OF-CHECKBOXGROUP'; // name, not title
     let checkboxes = JQuery("[name=\"ff_nm_"+A+"[]\"]:checked");

     if(  checkboxes.length > 0 ){  

         if( element.value.trim() == '' ){ // simple validation if the textfield is empty.

             if (message=='') message = element.name+" faild in my test.\n"
             ff_validationFocus(element.name);
             return message;
         }
     }
     return '';
}

Please replace "B" with the name (not title) of the the text element you are applying this to.
Replace "NAME-OF-CHECKBOXGROUP" with the name (not title) of your checkbox group.

This will check if anything has been selected and if, it will validate the textfield.

You can add this to all of your 3 textfields.

Regards,
Markus

Please Log in or Create an account to join the conversation.

Last edit: Post by TheMuffinMan.

How to make multi fields required if 1 check box is checked? 3 months 5 days ago #244883

  • Topic Author
  • ahmeds2
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 49
  • Thanks: 0
for above example, How if we have a checkbox not checkbox group? what we need to change in above code?

Please Log in or Create an account to join the conversation.

How to make multi fields required if 1 check box is checked? 3 months 3 days ago #244984

  • TheMuffinMan's Avatar
  • TheMuffinMan
  • Offline
  • Developer
  • Developer
  • Posts: 10064
  • Karma: 167
  • Thanks: 803
Hi,

sorry for the late reply, I had to take off a day yesterday.

However, it would be the same. It is laid out in a way to address all checkboxes, no matter how many.

Regards,
Markus

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
  • 2
Moderators: ForumSupport
Time to create page: 0.051 seconds

BreezingForms Pro 1.4.7 for WordPress Released!

Available in the membership section.

September Discount!

Massive discounts on all subscriptions!

Get Your Subscription Here

Quick Links

Downloads

BreezingForms

ContentBuilder

BreezingCommerce

Templates

Documentation

BreezingForms

ContentBuilder

BreezingCommerce

Apprendre BreezingForms (French Community)

Apprendre et maîtriser BreezingForms par des tutoriels et exemples, le tout en français

breezingforms.eddy-vh.com

Questions et réponses sur les forums de l'AFUJ

AFUJ

Special Offer

Summer Sale! All subscriptions at a special price!

Includes prio support, all of our current and future Joomla!® extensions and Joomla!® templates for the duration of your membership.

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!