1

I have the following form that is the template tied to a angular component. I'm able to retrieve the values tied to $ctrl.form when I submit which shows that the form is being tied to the controller, as expected, however, the $valid on the submit button does not work. Once I add the validator, the button always remains disabled as the form is not valid.

<div class="verification step-3">
  <form name="form" ng-submit="$ctrl.submit()">
    <fieldset ng-disabled="$ctrl.isSubmitting">
      <md-content class="md-no-momentum">

        <!-- username -->
        <md-input-container class="md-icon-float md-block">
          <label>Username</label>
          <input data-id="login-username"
                 ng-model="$ctrl.form.username"
                 name="username"
                 type="text"
                 required>
        </md-input-container>

        <!-- register button -->
        <div class="text-center">
          <md-button data-id="register"
                     class="md-primary md-raised"
                     ng-disabled="!$ctrl.form.$valid"
                     ng-class="{ 'btn-disabled': !$ctrl.form.$valid }"
                     type="submit"
                     ng-click="$ctrl.submit()">
            Create account
          </md-button>
        </div>

      </md-content>
    </fieldset>
  </form>
</div>

1 Answer 1

1

remove the $ctrl from the $valid. $valid use to check the form validation so you don't need to use the controller as reference

change this

ng-disabled="!$ctrl.form.$valid"

to this

ng-disabled="!form.$valid"

remove the ngClick also since you are using ngSubmit

 <md-button data-id="register"
   class="md-primary md-raised"
   ng-disabled="form.$valid"
   ng-class="{ 'btn-disabled': form.$valid }"
   type="submit"> Create account
 </md-button>
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect! It made so much more sense to have $ctrl but whatever... :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.