Show/Hide an element in view if a checkbox is or isn't chosen

  • witchypaws
  • Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
  • Posts: 26
  • Thank you received: 0

witchypaws created the topic: Show/Hide an element in view if a checkbox is or isn't chosen

Hi Guys

I have six fields, the fields 2-6 only shows in the form if the first field has a value ticked for each of the following fields

I would like to create a content builder view that shows the results of fields 2-6 only if they were chosen in field 1

i.e. field 1 (checkboxes, multiple items allowed) can be individuals, teams, organisations, business, government

If they tick individuals and government, then they are asked to fill out further options in dropdown multiple checkbox fields for those two categories

On the profile, we only want to show the results for the individuals and government fields if they were ticked in field 1 but hide if they were not chosen

i.e. the profile can look like this




Individuals
Directors, Entrepreneurs, Executives, Founders, Support staff

Teams
Boards, Committees, Executive, Leadership, Support

Organisations
Membership Associations, Non-profit Organisations, Peak Bodies, Purpose Driven Organisations, Schools, Social Enterprises

Business
Conscious Business, Contracted Agencies, Family Business, Non-profit Business, Purpose Driven Business, Small Business, Start-ups

Government
Local




but in this case we only want it to look like this as they only ticked individuals and government in field 1



Individuals
Directors, Entrepreneurs, Executives, Founders, Support staff

Government
Local




I understand how to show or hide field based on if it is empty or not but not quite sure the best way to do this as I don't know the syntax to show a field based on the value chosen in another field

Can you assist please

Thanks

Jacqui
#236791
  • Posts: 2561
  • Karma: 87
  • Thank you received: 344

mihaela replied the topic: Show/Hide an element in view if a checkbox is or isn't chosen

Hello,

If you have one Checkbox group element containing options "individuals, teams, organisations, business, government", then to show/hide fields based on selected checkbox options you need to use JavaScript visibility rules.

Please take a look at this piece of documentation regarding JavaScript visibility rules crosstec.org/en/support/online-documenta...s-in-javascript.html .

Here is a code for your example:
function ff_checkboxgroupname_action(element, action)
{
    opts=jQuery('[name="ff_nm_checkboxgroupname[]"]:checked');
    var ind = 0; 
    var tm= 0; 
    var org = 0; 
for (var o = 0; o < opts.length; o++) {
    if(opts[o].value == "individuals") {
          ind = 1;
          bfToggleFields('on','element','individuals',bfDeactivateField);
          }
    if(opts[o].value == "teams") {
          tm = 1;
          bfToggleFields('on','element','teams',bfDeactivateField);
          }
    if(opts[o].value == "organisations") {
          org = 1;
          bfToggleFields('on','element','organisations',bfDeactivateField);
          }

    }
if(ind == 0) { bfToggleFields('off','element','individuals',bfDeactivateField); }
if(tm == 0) { bfToggleFields('off','element','teams',bfDeactivateField); }
if(org == 0) { bfToggleFields('off','element','organisations',bfDeactivateField); }

} // ff_checkboxgroupname_action
In this code it is assumed that you have fields named "individuals", "teams" and "organisations" which are displayed in case the corresponding checkboxes are checked.

As for the view, when a certain record is entered in the Content Template by default only fields that were filled in that record will be shown.

Let me know whether you have managed to set this for your form.

Regards,

Mihaela
#236835
Moderators: ForumSupporttomeperica
Time to create page: 0.060 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