I have 2 textboxes and a submit button in a form. One which takes First Name as input and other one as Email. I am trying to validate the form by using angularjs. For the first name field, I apply
<div ng-class="{ 'has-error' : creatProspectSubmit && prospectCreate.FirstName.$error.required }"
This works perfectly and it highlights the textbox when there is no name in it. Another validation which I have added in the textbox is
<input type="text" name="FirstName" ng-model="FirstName" ng-required="true">
So when I click on submit, the textbox gets highlighted and the form does not gets submitted.
There is a different validation for email field.
<div ng-class="{ 'has-error' : creatProspectSubmit && prospectCreate.Email.$error.required || EmailValidate || prospectCreate.Email.$error.email}">
So this works good and it highlights the textbox if it satisfies the above condition. Other validation is
<input type="email" name="Email" ng-model="Email" ng-required="true">
The problem here is it highlights the textbox if the email address is wrong but when I click on submit it accepts the value maybe it is because ng-required = "true" is satisfied. How can I stop the form from submitting without writing any code in the submit button.
I tried adding the below code in the textbox but it disappears the textbox of Email.
ng-if = "creatProspectSubmit && prospectCreate.Email.$error.required || EmailValidate || prospectCreate.Email.$error.email"
I am struggling on this from 2 days. I do not want to write any code on submit button. All the validations should be done in the textbox itself. Any help would be appreciated.