Enum List Validation

Does anyone know how to perform data validation on a Enum List so that the user is required to pick ONE certain item in the list, but could also select that required option along with others.

For example, If I had the following list but wanted to require โ€œCatโ€ was selected.

  1. Cat
  2. Dog
  3. Bird

Accepted: Cat
Accepted: Cat, Dog, Bird
Not Accepted: Dog, Bird

Any help with this would be appreciated. Thanks!

Solved Solved
0 9 633
1 ACCEPTED SOLUTION

Interesting. I did not expect this particular issue in this situation. A better solution would be:

AND( TRUE, IN( "Cat" , [_THIS] ) )

If you use CONTAINS, that would also allow someone so select, say โ€œBobcatโ€, without selecting โ€œCatโ€ as well.

View solution in original post

9 REPLIES 9

IN( "Cat" , [_THIS] )

So simple yet it was making me bang my head against the wall. Thank you so much Marc!

You could use this awesome post by Matt showing how to make custom messages when the validation rule says it canโ€™t be save

I know itโ€™s kinda advance but itโ€™s a good resourse of improvement/knowledge

At first glance this seemed like the obvious answer. After trying to implement it makes it so that field does not appear at all in my form. Any other ideas?

Interesting. I did not expect this particular issue in this situation. A better solution would be:

AND( TRUE, IN( "Cat" , [_THIS] ) )

If you use CONTAINS, that would also allow someone so select, say โ€œBobcatโ€, without selecting โ€œCatโ€ as well.

I definitely overlooked the fact that CONTAINS could potentially create some problems. I tried your most recent post and it worked well and has been marked as the solution.

Do you know why adding the AND/TRUE will allow it to work? It seems redundant, as the logic creates the same end result.

I was kind of hoping you werenโ€™t going to ask, lol.

Its intention is to avoid a certain automatic behavior within Appsheet. But that is not for this exact situation. So really Iโ€™m not sure exactly why its needed here. I think it may just be some small edge-case glitch.

Consider the situation where you have a single-value column (Text,Enum,Number,etc), and you want to validate the input against a List somewhere, but you do not want to show a dropdown. Youโ€™d initially think to use a simple IN( [_THIS] , list-to-check ). However, Appsheet likes to automatically create dropdown lists when it sees a simple IN() expression in the valid_if, so youโ€™d get a dropdown. The common approach there is to basically create a logically-equivalent expression, but so itโ€™s not just a simple IN(). Both OR( FALSE , IN() ) and AND( TRUE , IN() ) accomplish the same thing.

So, even though your situation is quite different, since itโ€™s still a simple IN() in the valid_if, I figured the same solution would work.

Haha! Well thank you for taking the time to explain it to me! That makes perfect sense. Hopefully in the future I will now be able to figure it out on my own so I can keep the โ€˜unwanted questionsโ€™ to myself! lol

Thanks again!

I tried a slightly different version of your solution using โ€˜Containsโ€™ instead of โ€˜Inโ€™ and it works perfectly now.

Contains([_THIS],โ€œCatโ€)

Thanks again!

Top Labels in this Space