In a number of forms, there will be one or more required fields for the user to fill in. In our New Car screen, we will make the Car Name field required. First, let's inform the user the field is mandatory by putting a '*' in the placeholder text.
Thanks to the placeholder text and the asterisk, we have indicated to the user this field is required. But what if they ignore us and try to save the record without inputting a car name? Obviously we don’t want to save a car with no name, so we’ll have to create some “checks and balances” to make sure Method won’t actually let a user save a record with no car name. We can do this through use of conditionals.
A conditional is a way for Method to carry out different actions based on a certain condition. In our example, we want to check if the Car Name field is empty or not. If it’s empty, we want a “show message” to pop up, telling the user to add a name. If the field has a value in it, we want the record to save as normal!
The Conditional Statement action is done differently than other actions. Notice there is an If...then and an else connected by a blue line? This will be easier to explain when the statement is set up so let's add a condition.
This is the condition we are setting up: we’re checking if the “CarName” field is not empty. Note that the Internal Note shows up beside the Conditional Statement? It saves a lot of time to know what your conditional statement is asking.
Now, this condition can be one of two things: True or False. If the answer is “True - the field has a value in it”, then actions indented under If...then are done. If the answer is “False - , the field is empty”, actions indented under the Else condition are done. Let’s deal with If first.
There we go: if the CarName field is not empty, all the actions underneath If...then will run in order (which means the record will save as normal.) Now let’s deal with the other potential - if the CarName field IS empty.
Great! The show message action has been created.
Now, if a user clicks Save with nothing written in the field, the message will appear. And if the user has included a name, Save will save the record as normal!