Require Single Text Field based on a 'Checkbox Type' Choice field

  • 16 January 2019
  • 4 replies
  • 16 views

Badge +7

Hey Everyone,

     I'm working on a form and I'm running into issues requiring fields. I have one choice field that is set as check boxes. based on which option they select, determines which fields are required. Below you will see that the "Impact" field is the check boxes field I'm referring to. If a user selects "Cost Avoidance" from the "Impact" field it will require the "Initial Cost" and "Final Cost" fields. However, it does not require them if they also select "Labor Savings" in the "Impact" field. How do I require both "Initial Cost" and "Final Cost" fields when both "Cost Avoidance" and "Labor Savings" is selected? Thanks in advance for any help!

221999_pastedImage_1.png

222000_pastedImage_2.png 


4 replies

Userlevel 5
Badge +14

I'm not sure I've understood your requirements correctly, since some of them sounds to me to be contradicting...

but let's go step by step

you have to use validation rules to achieve your target.

If a user selects "Cost Avoidance" from the "Impact" field it will require the "Initial Cost" and "Final Cost" fields.

for this requirement validation formula might look like

inArray(ImpactNamedControl,"Cost Avoidance") && (IsNullOrEmpty(InitialCostNamedControl) || IsNullOrEmpty(FinalCostNamedControl))‍‍‍

However, it does not require them if they also select "Labor Savings" in the "Impact" field.

I understand this that it extends previous requirement.

and I understand this that if both "Cost Avoidance" and "Labor Saving" are selected then it doesn't matter what's the content of 'Initial cost" and "Final cost" fields.

combining the two requirements, it means that if one doesn't select "Cost Avoidance" you do not put any requirement on any of the other selections (ie. "Labor Savings") nor any requirements on whether cost fields are populated or not, ie if "Cost avoidance" is not selected, whatever (combination of) state/content of "Labor Savings" and cost fields should be accepted.

further, if "Cost Avoidance" is selected AND "Labor Savings" is not selected AND both "Initial Cost" and "Final Cost" are populated (1st requirement) the form should be accepted as well.

so we're left situations when "Cost Avoidance" is selected AND "Labor Savings" is not selected AND either or both of cost fields are empty - in these scenarios the form shouldn't be accepted and validation error should pop up.

so let's rewrite above into a validation formula, which might then look like

(inArray(ImpactNamedControl,"Cost Avoidance") && not(inArray(ImpactNamedControl,"Labor Saving"))) && 
(IsNullOrEmpty(InitialCostNamedControl) || IsNullOrEmpty(FinalCostNamedControl))‍‍‍‍

How do I require both "Initial Cost" and "Final Cost" fields when both "Cost Avoidance" and "Labor Savings" is selected?

this I understand as a completely different question/scenario since it negates above mentioned requirements.

so for this requirement validation formula might look like

(inArray(ImpactNamedControl,"Cost Avoidance") && inArray(ImpactNamedControl,"Labor Saving")) && (IsNullOrEmpty(InitialCostNamedControl) || IsNullOrEmpty(FinalCostNamedControl))‍‍‍‍‍‍
Badge +7

Ok, to make it clear. I need the "Initial Cost" and "Final Cost" fields to be required when the "Cost Avoidance" option is selected from the "Impact" field. Currently, it will require them if the user only selects "Cost Avoidance". IF the user selects both "Cost Avoidance" AND "Labor Savings", it currently does not require the field (which is not what I want). I am wanting it to require the fields anytime "Cost Avoidance" is selected. So, if you the user selects just "Cost Avoidance" it will require the "Initial Cost" and "Final Cost" fields and it will also require the "Initial Cost" and "Final Cost" fields when they select "Cost Avoidance" AND "Labor Savings". I have tried your rule above and it still does not require the "Initial Cost" and "Final Cost" fields when the user selects both "Cost Avoidance" and "Labor Savings".

Rule used: 

(inArray(Impact, "Cost Avoidance") && not(inArray(Impact, "Labor Savings"))) && (isNullOrEmpty(InitialCost) || isNullOrEmpty(FinalCost))

Badge +7

I was able to get the validation to work by removing the "not" from the 2nd Array statement. Thanks for your help!

Rule used: 

(inArray(Impact, "Cost Avoidance") && not(inArray(Impact, "Labor Savings"))) && (isNullOrEmpty(InitialCost) || isNullOrEmpty(FinalCost))

Badge +1

I have something similar but can't figure it out. I have a multiple choice field called "component" and if the "Apple" is checked then I need it to display the "Type of Apple" text field, If both "Apple" and "Banana" are checked then I need it to display both the text fields - "Type of Apple" and "Type of Banana" 

I can't do a screenshot of it because its on my work machine and am not allowed. 

Reply