Search code examples
angularjsangular-materialng-messages

ng-message doesn't work for select boxes


i have a material design select and i'm trying validating it using ng-message

<md-input-container class="md-block" flex-gt-sm >
   <label>Payment method</label>
   <md-select name="paymentMethod"  ng-model="payment.paymentMethod" flex ng-change="paymentMethodChange(payment.paymentMethod)">
      <md-optgroup label="Payment Method">
      <md-option ng-repeat="item in PayArr track by $index" value="{{item}}">{{item}}</md-option>
   </md-select>
   <div ng-messages="editForm.paymentMethod.$error" >
      <div ng-message="required">payment method required</div>
   </div>
</md-input-container>

my form name is editForm. i use this same scenario for input boxes and it works fine. i can't figure out why it doesn't work for select box. thanks guys for ur support


Solution

  • You didn't put the required attribute in md-select.

    <md-select name="paymentMethod" required  ng-model="payment.paymentMethod" flex ng-change="paymentMethodChange(payment.paymentMethod)">
          <md-optgroup label="Payment Method">
          <md-option ng-repeat="item in PayArr track by $index" value="{{item}}">{{item}}</md-option>
       </md-select>