Validate Form Inputs
Server-side Validation of Inputs
This lesson is part of the Developer Online Class for OutSystems 9 course.

let's see how the OutSystems Platform validates inputs submited by the end user
we will start with mandatory fields and data type validation
and we will do this here in the ProductDetail page
the first thing I want to show you is that
in our form actually in the button
that we have in our form we have a property
which is called Validation the platform supports validation of the user inputs in
the browser
also known as client side validation and in the server
also known as server side validation so here the values
we have 'Server' meaning that this is validation of the inputs
server side we also have 'Client & Server' meaning that we have
client side validation and server side validation
and finally you can also set the
button Validation property to 'None' meaning that
no validations will be performed by the OutSystems Platform
now what happens here and and let's let's first set this has
server side validations what happens here is that
in our inputs as you've seen in the previous lessons
we've been setting the mandatory property
according to according to
the definition of our entity so here the Name
and the Price are both mandatory attributes
this means that on this form the name
and the price will need to be filled in when the form is submitted
the mandatory attributes are validated to see if the end-user
has filled in the data on these input This is
mandatory field validation the platform also
checks data type validation meaning that
the information that the user types in in each one of these inputs
needs to match the data type of that
attribute so for instance here this is the
price input it's bound to the price
attribute of the entity and the price attribute of the entity
is a currency so if the user types in here
something which is not a currency we will have also
an error for that now how do we trigger this
this automatic valuations we need to set
here this parameter
Validation this means that the platform will
validate all these mandatory attributes and data types
in the server and
in the screen action of this Save button
in this action here you must
check if the form is
if the information that we have in the form is valid or not
and we will do this here by adding a piece of logic
with an if to
validate if our form is valid or not
and and the condition here for this is
we're going to use the ProductForm
which is a form we have on the page besides the Record
property we've been using we still have here another property
which is the Valid property and this means... let me just
select here... this means that if any
of the inputs we have in the form is not valid
then this property will have
a false value because this is of boolean data type
so this means that this is false and if this is false
in that case let me just add here
an End node we don't want to continue
we don't want to continue to send the information to the database
so I need here to swap these connectors
use here this option so if the form
is not valid I will not continue to send the data to the database
this means that the save action will end the preparation will be executed
and the form the form will be rendered again
with the indication that the inputs
are not valid so let's see this
in action in our application
okay so let's go here to the products
and let's create a new product and before we continue let me just
go back here to the development environment and set
a break point here in this Save action
and launch the debugger
here okay so let's go back to our application
an let's try to save this new product without giving it
a name remember that a name is a mandatory attribute so when we
Save we're stopped in the breakpoint
when we save let me step over
the valid property the valid property of the form
is false and it's false because the input
for the name is not valid because I haven't filled in the name so let's
and see what happens in our application
and there you have it you have the indication that the name
is a required field so we need to fill in here
'USB Camera' for instance and you see that
for instance the price is a mandatory attribute we filled in
with zero if you remove this value
and we tried to save it again
again we'll have this property
as not valid let me just here
remove the break point so that we can continue testing
let's go back to our application so this is a required field
and if I type here something which is not the currency for instance
some text and I try to save this will tell me that
this is a currency and the value that I entered here
is not a currency and if I type in
something like this and I save
then here I have my new product
and the validations are working that's it