You are viewing limited content. For full access, please sign in.

Question

Question

Field Rules Dilemma while trying to Hide/Show fields.

asked on January 12, 2021

I am working on a form with a collection of field that require pretty extensive field rules to hide/show some fields based on selections. Unfortunately, Forms logic for field rules on the surface do not seem to be expansive enough. Wondering if anybody has accomplished something similar

 

Here is a brief explanation:

  1. Field A (Drop Down) 
    • Option 1
    • Option 2
    • Option 3
  2. Field B (Radio)
    • Option 1
    • Option 2 
  3. Field C
  4. Field D

 

Here are the rules I am struggling with :

1. Show Field C , when:

  • Field A (Option 1 or Option 3 selected)
  • Field B (Option 1 selected)

2. Show Field D, when:

  • Field A (Option 3 is selected)
  • Field B (Option 2 is selected)

3. Show  Field D when

  • Field A (Option 2 is selected)

* It should be noted that selecting Field A-Option 2 automatically hides Field B.  

 

The issue I have is that since rule 2 & 3 act on the same field it creates a situation where I am not getting the behavior I am expecting from when I choose  Field A-Option 3. I end up with an extra field displaying that I do not want.

 

I hope I explained this clearly. 

 

 

 

1 0

Replies

replied on January 13, 2021

Hi Lawrence,

This can be accomplished using a Javascript switch. You can set it that when your field 2 is set to hide field 3. I have used this for several cases for the scenario where I want to hide either a certain field or option from a dropdown or checkbox, but I either have a lookup or additional rules looking at a single field.

//Detect when a change is made to Option 2
$('#Field2').change(function(){
    
// If changed and the option we have selected to hide option 3 is picked, assign hidden attribute
  if($('#Field2).is(':checked')){
      $('#Field3').attr('hidden','true');
    }    
  
    if($('#Field1').is(':checked')){
      $('#Field3').removeAttr('hidden');
    }
});
3 0
replied on January 13, 2021

Because Forms doesn't allow grouped conditions, I handle these situations with a hidden field; In the hidden field, I use a calculation to check the condition, then I use that field for my rule.

For example,

Create a hidden field like Show_Field_D

Set the calculation to be =OR(FieldA.Option2,AND(FieldA.Option3,FieldB.Option2))

What this does is generate a TRUE/FALSE result in the field

If FieldA.Option2 is checked

Or FieldA.Option3 and FieldB.Option2 are checked

Then the value is TRUE, otherwise it's FALSE

 

On your field rule, you check set your rule to:

Show FieldD When Show_Field_D equals TRUE

1 0
replied on January 20, 2021

Hey Jason, Thanks for the advice. I am trying to implement this and keep getting a syntax error in my formula. Also, I assume this field is meant to be a number field since it is the only field that contains the calculation option.

Here is what I have : =OR(HybridElectric_Vehicles_Collection.HE_Powertrain.Hybrid (conventional),AND(HybridElectric_Vehicles_Collection.HE_Powertrain.Plug-in Hybrid,HybridElectric_Vehicles_Collection.HE_ReportFuel.Estimate: I'm not sure how much alternative fuel was used.))

*The bold text above represents the value of the options in the drop down lists.

Below are references from my process. 

  • HE_Powertrain

         

  • HE_ReportFuel

        

0 0
replied on January 20, 2021

Hi Lawrence,

It does not need to be a number field, a single line field also has the formula/calculation option in the Advanced tab and I usually do that so I can just take the text TRUE/FALSE result, otherwise you'd need your calculation to output a number.

I didn't realize you were using a collection, so that does change things a bit. For a calculation to work with fields in a collection, you'll need to use the INDEX function to ensure it is only evaluating a single value and not the entire collection.

You would then use the ROW() function to ensure it is referencing items from the "current" row associated with each calculation field.

Basically you wrap each collection variable in it's own INDEX function like so,

INDEX(variable,ROW())

Also, make sure to pick the variables as-is from the drop-down variable menu rather than typing them because even if the choice has spaces and such, those shouldn't be there when you choose the variable because variable names can't have spaces or special characters.

1 0
replied on January 20, 2021

I will give this a shot.

Also, In my attempt ,that I showed you, should I not have input the drop down choices as they appear (they have spaces)?

 

0 0
replied on January 25, 2021

There's a difference between the visible text for the choice and the "value" of the choice. The "value" is what should be in the calculation.

Did you type those values in manually, or did you select them from the variable dropdown menu (the > button above the calculation field)?

Under the list of the choices there's the "Assign values to choices" checkbox; I'm not sure if you need that enabled, but that's how you'd set values manually.

I try to set shorter values, for example, although your choices are "Actual: I know how..." and "Estimate: I'm not sure.." I would just set the accompanying values as "Actual" and "Estimate"

1 0
You are not allowed to follow up in this post.

Sign in to reply to this post.