Data form validation is a very common use case in web development. The end user will know immediately if they've made a mistake when you create validation rules in your application.
In this recipe, we'll take a look at two examples on validation. In the first example, we'll use a component and check data based on a few simple validation rules. In the second example, we'll use a popular Ember add-on to make things easier.
In a new application, create two components and install the validation add-on:
$ ember g component val-example $ ember g component val-example2 $ ember install ember-cp-validations
The
val-example
component will be the first example. Theval-example2
component will be the second example using theember-cp-validations
add-on.Update the
val-example.hbs
component template file:// app/templates/components/val-example.hbs Enter Age:<br> {{input value=num}} <button {{action 'check'}}>Check</button><br> {{error}}<...