In this section, we are going to revisit the topic of validation.
I know what you're thinking.
We've spent hours on these forums.
What else could we possibly add?
Forms are one of the most complex types of UI to create.
There are various scenarios and edge cases we need to account for.
The forms we've developed are incomplete.
There are two major issues with the registration form.
Firstly, we're not checking if the password fields match.
Users can create an account without verifying their inputting the correct password.
Secondly, it's possible an email can be taken if an email is taken.
We should inform the user Firebase will reject a user's registration if an email is registered with
our app.
We aren't giving the user enough information to fix their mistake.
We can't fix these issues with angular validator class.
It does not come with functions for addressing these problems.
In these cases, we will need to create custom validators.
This entire section will be dedicated to developing custom validators.
I chose not to talk about custom validators because we need to learn our SJS and Firebase first.
Now that we've covered these two topics, we can come back to form validation.
Knowledge of these topics will help tackle these problems.
Let's get started.
Custom validators can be defined as classes or functions.
Both options are viable for this course.
We will focus on class validators.
Are much more common for our first validator.
We are going to check if the passwords match.
Let's discuss how we will design this validator throughout most of this course.
We have been registering validators with form controls.
Angular will supply validators with access to the form control.
As a result, validators will have access to the value to perform validation during the development
of this validator.
We might attempt to add the validator to the confirm pass form control.
This solution might seem like it'll work, but there's one problem we need access to the password form
control for its value.
Obtaining this value is possible but tricky.
It's going to become challenging to design a validator like this.
Luckily, there's an alternative way to add a validator to a form.
We can add validators to form groups.
By doing so, we will be given access to all form controls registered in a group.
It's going to be much easier to design the validator that has access to the entire group whenever you're
designing a validator that needs access to multiple controls.
Consider designing it in a way that has access to the form group as opposed to assuming it'll be added
to a single form control.
Let's generate a class for our validator inside the command line.
Run the following command Nji G class register of validators.
I'm introducing a new sub command called Class, as the name suggests, this command will generate an
empty class for us.
Two files will be created.
One of the files is a test file.
We can safely ignore this file.
Let's open the class file in our editor.
By default, the Seelye will export the class for us.
Great.
We've got a class for writing our validator.
Admittedly, we could have created the class ourselves.
However, I think it's always good to know what the Seelye can offer in the next lecture.
We will begin writing the logic for validating the password fields.