Validation of multiple fields

Validation of multiple fields

  

Hi Everyone,

I was wondering whether is it possible to validate multiple field with the same condition - a kind of loop through the widgets that are specified in advance?

As an example, I have a form with multiple fields of type integer or decimal and all of the fields should be greater than 0. Writing its own validation for each of them it's quite time consuming and making the action screen look awful...

Thanks in advance!

Hi Rok,

As in Server side you are stuck with the variables and the widgets, each being an individual piece of code, without an "array" of widgets, you can't do this server side (I'm not aware of a way to do it)

Client side you have two options. 

1. Set the min to 0 on all input of type numeric, through the extended properties,

2. Use JavaScript, and than you will have access to an array, depending on your code/selector.

Cheers

Eduardo Jauch

Eduardo Jauch wrote:

Hi Rok,

As in Server side you are stuck with the variables and the widgets, each being an individual piece of code, without an "array" of widgets, you can't do this server side (I'm not aware of a way to do it)

Client side you have two options. 

1. Set the min to 0 on all input of type numeric, through the extended properties,

2. Use JavaScript, and than you will have access to an array, depending on your code/selector.

Cheers

Eduardo Jauch


Thanks Eduardo! I would a possible solution for this one altough I am not able to replicate it - it is also quite an old post so not sure whether still workable.

https://www.outsystems.com/forums/discussion/5763/check-multiple-variables-with-single-action/

Do you think this could be accomplished?

Solution

Hi Rok,

The solution proposed in the topic you linked isn't even the solution to the question of that topic...

You have a lot of controls you want to make server side validation.
And server side validation is very important, as you don't know if the user changed something client side that would mess with client side validation (it is at his side, so he CAN do it).

The problem is: Server side, you don't have an "array" of inputs that you could iterate through. 

So, one way or another, you will have to deal with each one of them one by one. 

But there are things you can do. If you have "standard" validations that will be applied to most of them, you can do something a little different.

Create an action that executes one or more validations, but for a single type of input (both data type and business concept). It will receive as input the value of the variable bound to the type, and will return as output a validation message, empty if the validation is ok, with the message if not.:

Than, you can do this for each input you have in your page:

Now, you only need a single "assign" node to validate your inputs. Much "cleaner" than have to append all inputs to a list to iterate through than to call the action...

Cheers,
Eduardo Jauch

Solution

Many thanks Eduardo! Much better then evaluating one by one!