Reputation: 4126
If i have a registration form and a button to submit this form, i want button to be enabled only if form is valid and both password and repeat_password are the same.
<div class="form-group">
<button type="submit" ng-click="createUser()" ng-disabled="form.$invalid && !(user.password == user.repeat_password)" class="btn btn-success">
{{user.password == user.repeat_password}} {{form.$invalid}}
</button>
</div>
the problem ive got is, that if whole form is valid and passwords are the same button is enabled which is grate, but if form is valid button is always active, and it doesnt take the part where passwords has to be the same in to account. How do i solve this?
Upvotes: 0
Views: 49
Reputation: 64695
It's just your logic being off.
You want it disabled if the form is invalid, or if the password is not the same as repeat_password. But you are saying the form has to be invalid, AND the password has to not be the same as the repeat password.
You just need to change
form.$invalid && !(user.password == user.repeat_password)
to
form.$invalid || (user.password != user.repeat_password)
Upvotes: 2