1

I have two inputs for validating email and password. I can see individuals of the following works:

myForm.$error.required

validating input form with required input value and

myForm.email.$valid

validating my regex email

If i was to print i.e. {{ with the above code}} i can see the boolean result of the validation for both input and its correct. However when I use ng-disabled on button with both expression it doesnt work but if i put ng-disable with only one expression I can see it does work but I am unable to place both expression i.e.

<button type="submit" ng-disabled="myForm.$error.required && !myForm.email.$valid">Sign in</button>

Currently the result becomes true based on the first expression but i thought && meant both condition needs to be met in order to result true ? Could it be because the ouput is true + false = true ?

georgeawg
  • 48,608
  • 13
  • 72
  • 95
hello world
  • 385
  • 5
  • 24

2 Answers2

1

true + false doesn't mean true && false, it means true || false,

that's why you don't get the right behavior, so:

<button type="submit" ng-disabled="myForm.$error.required || !myForm.email.$valid">Sign in</button>
El houcine bougarfaoui
  • 35,805
  • 9
  • 37
  • 37
0

You should use ng-disabled="myForm.$invalid" if you want to disable the button while the whole form is invalid.

In case you want to disable the button if the email is not provided or email is not valid so you should use || instead of && so the button will be disabled in both cases.

Abubakr A.Hafiz
  • 269
  • 3
  • 10