The first option we have when working with forms is to disable the submit button if the form is invalid.This approach is OK for very small forms such as login forms, where we only have 2 fields (user/email and password).Place the Button on the HTML form and set the use Submit Behavior option to true. Dev Extreme editors may belong to different validation groups.To specify which group the Button must validate, use the validation Group option.
For this example we will use Bootstrap (v3) framework for the CSS styles.
However, specially when working with enterprise projects, we have forms with lots of fields.
And disabling the submit form when the form is invalid is not appropriate. For this example, we will consider a field has validation error when the field is not valid and it has been touched (meaning it has received focus).
Let’s take a look at a different approach in the next example. Please check the references at the end of this post for more information about the states of form controls.
We can use Angular You can also create a Helper or Util class in your project with these functions so you do not repeat the code in all your form components or you can create a super/base form class and use Angular inheritance.
This is because the code above will only work if you do not have Form Groups.