Validation rule for required field based on a multi select choice field
Need to know the validation rule for a required field based on a multi select field. My research shows I have to use “inArray”, but it is not working for me. Example requirement:
Field 1, “IT equipment” with choices: computers, monitors, accessories (multi-select)
Field 2, “Accessories” with choices: mouse, keyboard, headphones (mutli-select - and only appears if ‘accessories” is selected from Field 1
Field 3, “Number of computers”
Filed 4, “Number of keyboards”
Q1. Need validation rule to make a multi-select field (Field 2) a required field based on selection of multi-select field (field 1)
Q2. Need validation rule to make a text/number field (field 3 or field 4) required based on multi-select field (field 2)
Any assistnace would greatly be appreciated.
Page 1 / 1
Hi @isabellamai
Let me get this right,
Field2 only appears when Field1 has “Accessories” select. Done
Does Field3 and Field4 have any rules for Show/Hide?
and if field2, field3 and field4 appears, they have to be required via validation rule, right?
Field 3 and field 4 will show/hide based on the other choices e.g., number of computers or number of monitors.
I can get to show/hide, but I need to make sure that the field 2, 3, or 4 must have data based on what is selected in field 1 or field 2...so field 3 would display when computers is selected from field 1, and field 4 would display based on field 2...but data must be selected in field 2 IF “accessories” is completed and data must be entered in field 3, if computers is selected, and field 4 if keyboards is selected. Thanks Garrett for taking a look. I used not(inArray(Accessories,”Keyboard”),isNullOrEmpty(Number of Keyboards)) - but the field is not enforcing this validation of data must be entered? What am I doing wrong...and I am using the ‘Named Controls’.
@Garrett - please note, FIelds 1 and 2 should be set up as ‘Checkboxes - allow multi-selections)
Hi @isabellamai
You will need 3 rules to Show-Hide Field2, Field3 and Field4. You will need another 3 rules to Validate Field2, Field3 and Field4. (Later), You may wish to combine the Validate into a single rule.
I have provided the summary for the fields 2,3,4. I have provided screenshots for Field2 Rules. I believe that you should be more than capable to resolve field3 and field4 from the summary.
Field2 - Show-Hide → Hide when not(Field1 = “Accessories”) → Show when Field1 == “Accessories” FINAL → not( contains( field1, “Accessories”))
Field2 - Validate → when Field1 == “Accessories” AND length(Field2) == 0
Field3: Show / Hide fields | Validate field
Field3 - Show-Hide → Hide when not(Field1 == “Computers”) → Show when Field1 == “Computers” FINAL → not( contains( field1, “Computers”))
Field3 - Validate → when Field1 == “Computers” AND Field3 == “”
Field4: Show / Hide fields | Validate field
Field4 - Show-Hide → Hide when not(Field2 == “Keyboard”) → Show when Field2 == “Keyboard” FINAL → not( contains( field2, “Computers”))
Field4 - Validate → when Field2 == “Keyboard” AND Field4 == “”
Output
@Garrett - thank you, thank you, thank you for taking the time to respond to this question. It’s interesting that the IsNullOrEmpty doesn’t work for the multi-select field. I read somewhere that it had to do with the fact that the list doesn’t recognize the selections as an entry. This was the first time I have used length in a validation formula.
@Garrett - as an extension to this problem...when field 3 is filled ‘number of computers’, additional fields would be required based on the number e.g., if 5, fields: ‘computer number 1’, ‘computer number 2’, ‘computer number 3’, ‘computer number 4’, ‘computer number 5’ would be required fields. I tried to use the same concept for the show/hide for the invalidate, but it does not work e.g., and(not(contains(NumberOfComputers,”2”),and(not(contains(NumberOfComputers,”3”)and(not(contains(NumberOfComputers,”4”),not(contains(NumberOfComputers,”5”))))))
If I use the same above concept, how would I write the rule that would work as my combinations are not working. Is there a rule that allows you to say, If Number of Computers is 1 thru 5, then fields, Computer Number 1, Computer Number 2, Computer Number 3, Computer Number 4, and Computer Number 5 are required fields?
@Garrett - hoping the solution allows me to combine rules versus creating potentially up to five separate validation rules...in my case, I will need to create about 20-30 fields for the computer name and am trying to find a way to consolidate the rules versus creating up to 20-30 rules per field
Hi @isabellamai
Using individual rules for each field - PC1 - PC5
Validation is feasible
Just that it would be very tedious or monotonous as each field needs 2 rules (1 for ShowHide, 1 for validation)
Hi @isabellamai
Your other question - combine Validation - my mind is a blank on this
@Garrett - thank you. I modified the formula slightly because I did not need to reference the field 1 and the below also works: not(greaterThanOrEqual(NumberOfComputers,1) && {Self}==””
Thank you for saving me time and showing me the greaterThanOrEqual option - as that would have saved me some work on the show/hide.
My question on combining validation was resolved by your solution as I was thinking I needed to do something like: {Self} && contains(NumberOfComputers,1) || contains(NumberOfComputers,2) || contains(NumberOfComputers,2) || etc.
@Garrett - ignore - I think I know what caused my error