Possible to prevent users entering 'other' value that actually exists in choice list?

320
3
11-28-2023 03:33 PM
ChristopherCounsell
MVP Regular Contributor

We have a select_one question with a list of values including 'other'.

When users choose 'other', a relevant question appears that allows them to type in value not in the list.

We often update the choice list with frequently used 'other' values.

E.g. what's your favourite colour - red, blue, green, other?

gets updated when a lot of our users enter other > yellow:

what's your favourite colour - red, blue, green, yellow, other?

What we want to be able to do is stop users from entering 'other' > yellow, after the value has been added to the list.

Is there a way that the second question for the manual text entry can check that the value actually doesn't exist in the choice list already?

0 Kudos
3 Replies
MattEdrich
Occasional Contributor

I have not tested this, but I believe you could accomplish this using a regex() conditional.

Basically, in the constraint (L) column of your form, for the favorite_color_other row, add this:

regex(.,'^(?:(?!yellow|red|blue|)*$\r?\n?)')

This particular regular expression should match any input that doesn't contain the strings 'yellow', 'red', or 'blue'. However, I am not the greatest with regular expressions myself, so you may have to consult a source like this to nail down the specific syntax. Also, make sure to experiment and test each regex attempt to make sure it's behavior is doing everything you want it to and nothing you don't want it to!

0 Kudos
ChristopherCounsell
MVP Regular Contributor

Good idea but gets a bit unwieldly when the list is longer (ours are in the 20-100 value ranges). Maybe something like what you've mentioned, but using JavaScript function is possible, but overkill for the scenario.

Unless someone has a better idea we'll look at regex for smaller lists, and put a hint in the 'other' question for recently added values so the end users are aware. 

0 Kudos
MattEdrich
Occasional Contributor

Yes regular expressions can indeed become unwieldy, and they can get there pretty fast too! You have likely considered this already, but if you can find common character stems/sequences amongst the words you wish to prohibit as responses, that can sometimes dramatically shorten the regex function!

An alternative approach for you, particularly for a longer list of exclusion words, could be to compile them in an external .csv that is referenced by a pulldata() calculation immediately following the text input. If the input matches a word in the list, a boolean switch (using an if() statement on the pulldata() calculate field) triggers an error note to display, telling the user that such an entry has already been submitted. It might even be possible to connect the text input itself to this boolean in such a way that if the error note is triggered, the text input itself is also reset to an empty string.

All that would probably take some serious jiggering if it is even possible....just a morning spitball for you!

0 Kudos