Validating input fields 247 sexi punjaib
The fields are marked red by default, because empty fields are invalid but… Also, the fields are still red while focused for the first time. We are going to do that by adding the class if the field was in focus at least once but has since been blurred.This ensures that the first time a user focuses the field, the error won’t appear right away, but instead, only when the field is blurred.
We'll be talking more on forms using Angular (just like our other article: Submitting AJAX Forms: The Angular JS Way). We'll focus on client side validation and using the built in Angular form properties. See the Pen Angular JS Form Validation by Chris Sevilleja (@sevilayha) on Code Pen Now that we know what we want, let's get to building.
If you’ve followed along, you know about controlled inputs and simple things they enable, like disabling the Submit button when some fields are missing or invalid. While a disabled button is nice, the reason for that is not immediately apparent to the users. This is an important question to ask yourself, as different requirements might warrant different error representations. The way you want to display errors influences how you might represent them.
Now, to mark the bad inputs, we need to ask ourselves a couple of questions. Well, it’s all about the experience you want to provide. For the purpose of this post, I’m going to do with the simplest one — marking red the bad inputs, without anything else.
Angular provides properties on forms that help us validate them. We only want it disabled if our form is input field requires a valid email.
They give us various information about a form or its inputs and are applied to a form and inputs. This is a good practice since we will handle the validation ourselves. ng-valid and ng-invalid will automatically determine if an input is good based on the rules placed on it in your form.