Data Type validation depending on drop down list.

Dan Ratiu asked on November 26, 2020 14:47

Hello,

I want to perform data type validation depending on the type that is selected from a drop down list. The drop-down list values are: int bool string date json. I want to present an error if the users enters data that cannot be converted into the selected drop down type. For example:

  1. int is selected - the input value in text field needs to be an integer.
  2. bool is selected - the input value in text field needs to be "true" or "false".

...and so one.

The only response that I came up to is to write a macro that would handle all these cases but the code kind of piles up and maybe a better solution exits.

Thanks.

Recent Answers


David te Kloese answered on November 27, 2020 10:49

You could take a look into create multiple fields that hide/show based the value from the dropdown.

so

  • dropdown selection with the different values
  • checkbox for bool
  • text for text
  • int for numeric value
  • ... etc.

this does not require any customization or custom development. But might be a bit messy to keep track of the different options and such, and you have a lot of different fields. You would also need to implement the same logic when using the data.

--

A much cleaner solution would be to create a custom control that would handle all validation and the different controls but still store it in one field. You can make it as dynamic and flexible you like.

some info in the docs: docs.xperience.io/.../example-developing-custom-form-controls

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.