Mission 3 - 5: Field Validation

Validating required fields

Updated over a week ago

In the previous mission, we added functionality to the Save button so that it would go back. 

However, the save button may give an error because it doesn't validate if the required fields are filled in, or the text entered may have surpassed the maximum length.

In our New Car screen, we will make the Car Name field required. This can be done by setting up a Validation rule. For more information on how to validate fields, please see our article Field Validation

Adding a Validation Rule

1. Click the down arrow ( ▼ ) on the CarName field and select Validation Rules.

2. This will take you to the Validation List for the CarName field. There will already be one rule in there: Field Maximum Length. This validation rule is there because the field itself will only take 255 characters, so Method knows to put it in there.

If the field were required on the table level (which we didn't do for the CarName field), then the rule Field is Required would automatically be added. 

However, we need to add it manually for now. Select it to add it to the validation rules. 

3. Close to the Validation Window, and then close the screen.

When you look at the screen, do you see how the CarName field now has a red asterisk indicating it's a required field? This is automatically added when you add the Field is Required validation rule to it. 

Also, if you try and hit the save button, you will be prompted that a field is required. Try it! It works!

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!

Coming up next...

The New Car screen is pretty snazzy, however, we should put the save button also at the top of the screen. This provides a better experience for users on mobile. We'll do that in the next mission!

Previous Mission                         Next Mission

Did this answer your question?