Validation works with several specific Ionic 5 UI components such as:
In this sample, using validation is demonstrated for the Input component but any other component indicated above gets this property by default if included in the Form.
- In the DESIGN panel of the App Builder, and open the PALETTE panel on the left.
- Drag and drop the Form component to the Content area:
If you now unfold the Menu folder and select any of the files on the OUTLINE list, this particular component will get selected and its properties list will be shown on the PROPERTIES view on the right. It will also be selected on the breadcrumbs chain on top of the mobile frame so that you can see its nesting and easily switch between the other related page components:
- To review the properties that can be defined for validation purposes, go to the page PROPERTIES view on the right and unfold the Validation folder under the Form Control section:
Different UI components can have different sets of validation properties
- Set the Show Validation Errors property to True.
- For Required, also select true:
- Now, define the other validation properties one by one as follows:
- Min = 1
- Message for Min = not enough
- Max = 20
- Message for Max = too many
- Pattern = Only numbers:
- To make the input field more user-friendly, let's modify the component label: unfold the Label folder and change its default text, for example, Enter a number: . Also, change the Placeholder property to Enter:
- You might also like to disable the Header Toolbar Title:
- You can now save your work and click the TEST button in the App Builder Toolbar to run the app in the preview and test how validation works for the input procedure:
Updated 2 months ago