What i want to realize is two input fields which i want to compare. If same, form has to be valid. Otherwise, invalid. This is the code:
<form name="form" class="css-form" novalidate>
E-mail: <input type="email" placeholder="[email protected]"
ng-model="user.email" name="uEmail" required/>
<span class="error" ng-show="form.uEmail.$error.email">
Not valid email!</span>
Repeat e-mail: <input type="email" placeholder="[email protected]"
<span ng-if="user.email != repEmail">
E-mail address are not same!
The problem is, although these fields are not same, it is true:
form.$valid == true
Thus, how can i change the validity of form so that it can be false if the input fields are not same (although they are valid e-mail addresses)
You can use two methods here. You can either use angular-ui's validator directive (which is probably the easiest way to go), or you can write you own directive.
If you decide to use angular-ui's validator, it would look something like this:
<input name="email" required ng-model="user.email"> <input name="confirm_email" ui-validate=" '$value==email' " ui-validate-watch=" 'email' "> <span ng-show="form.confirm_emal.$error.validator">Emails do not match!</span>
just change the type to email
Repeat e-mail: <input type="email" placeholder="[email protected]" ng-model="repEmail" required/>
instead of just using
form.$valid && user.email == repEmail