1

I have this simple form:

<form name="assignCtrl.carrierForm">
     <md-input-container class="md-block">
            <label>Company Name</label>
            <input required name="carrierName" ng-model="assignCtrl.searchKeyword">
            <div ng-messages="assignCtrl.carrierForm.carrierName.$error">
                <div ng-message="required">This field is required.</div>
            </div>
     </md-input-container>

    <md-input-container class="md-block">
        <label>Company Email</label>
        <input type="email" name="carrierEmail" ng-model="assignCtrl.companyEmail" required
                               ng-pattern="/^.+@.+\..+$/" minlength="5" maxlength="100"/>
        <div ng-messages="assignCtrl.carrierForm.carrierEmail.$error">
             <div ng-message="required">Email is required.</div>
             <div ng-message-exp="['pattern', 'minlength', 'maxlength']">Please enter a valid email
                                address.
             </div>
        </div>
     </md-input-container>

    <md-button type="submit" ng-disabled="assignCtrl.carrierForm.$invalid" ng-click="assignCtrl.createAndAssign()">Create and Assign
    </md-button>

</form>

It is not being validated! ng-messages do not appear at all.

form.$error is also empty:

{{assignCtrl.carrierForm.$error | json }}

What could be the reason?

8
  • 1. Try to rename assignCtrl.carrierForm - > assignCtrlCarrierForm (all over the code) 2. Add ng-form direcitve Commented Jun 13, 2016 at 10:32
  • @Vitalii can't do 1! As I am using controllerAs syntax Commented Jun 13, 2016 at 10:34
  • md-input-container is this some kind of directive? Commented Jun 13, 2016 at 10:36
  • @Vitalii docs.angularjs.org/guide/animations Commented Jun 13, 2016 at 10:39
  • yeah! it is an angular-material directive Commented Jun 13, 2016 at 10:41

1 Answer 1

1

So, I found my mistake! In my huge html file, the form in the question turned out to be inside another form by mistake! That's why, the inner form was being removed! So, I removed the outer form and everything is just fine!

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.