Crixx93
Crixx93

Reputation: 777

Submit validation with angularjs 1.4 not working

I have a form and I want to disable the submit button until all fields are valid. For sample:

<form ng-submit="registerForm.$valid && register()" novalidate>
  <div class="input-group">
    <input type="email" class="form-control" class="ng-pristine ng-invalid" placeholder="Email" ng-model="user.email" required>
  </div>
  <div class="input-group">
    <input type="text" class="form-control" class="ng-pristine ng-invalid" placeholder="Username" ng-model="user.username" required>
  </div>
  <div class="input-group">
    <input type="password" class="form-control" class="ng-pristine ng-invalid" placeholder="Password" ng-model="user.password" required>
  </div>
  <div>registerForm is {{registerForm.$valid}}</div>
  <input type="submit" class="btn btn-default" value="Register"
        ng-disabled="!registerForm.$valid"
        ng-class="{'btn-success': registerForm.$valid}">
</form>

The problems seems to be that the $valid variable is undefined, because the line bellow does not display the value:

<div>registerForm is {{registerForm.$valid}}</div>

And the button always stays disabled. How can I solve it?

Upvotes: 1

Views: 38

Answers (1)

Lex
Lex

Reputation: 7194

Try giving your form a name.

<form name="registerForm" ng-submit="registerForm.$valid && register()" novalidate>

Upvotes: 1

Related Questions