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
    – Drag13
    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?
    – Drag13
    Commented Jun 13, 2016 at 10:36
  • @Vitalii docs.angularjs.org/guide/animations
    – T J
    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!

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.