我用谷歌搜索了它,但我得到了基于jQuery验证的答案。希望我能从这里得到答案。
我在其他形式中使用相同的ng-class,它们似乎与has-error类一起工作正常。标签受has-error类的影响,但不受select2的影响。
<div class="row">
<div class="form-group col-sm-12" ng-class="gdForm.$submitted && gdForm.company.$error.required ? 'has-error' : ''">
<label class="col-sm-3 control-label">Company</label>
<div class="col-sm-9">
<select ng-model="formData.company.company_id" class="form-control select2" style="width: 100%;" required>
<option value="" selected="selected" disabled="disabled"></option>
<option ng-repeat="company in companies | orderBy: 'company_name'" value="{{ company.company_id }}">{{ company.company_name }}</option>
</select>
<span class="help-block small"
ng-show="gdForm.$submitted && gdForm.company.$error.required">
<i class="fa fa-warning"></i> Company is required.
</span>
</div>
</div>