我在这里有一个简单的Angular表单:
<form class="form-horizontal" role="form" name="alertForm">
<div class="form-group">
<label for="cautionMultiplier" class="col-sm-2 control-label">Yellow Multiplier</label>
<div class="col-sm-5">
<input type="number" min="1" class="form-control" ng-model="alert.cautionMultiplier" id="cautionMultiplier" name="cautionMultiplier" placeholder="Ex. 2" integer required />
<span>{{alertForm}}</span>
<span class="alert alert-danger help-block" ng-show="alertForm.cautionMultiplier.$error.number && alertForm.amount.$dirty">
The value is not a valid integer
</span>
<span class="alert alert-danger help-block" ng-show="alertForm.cautionMultiplier.$error.min ">
The value must be at least 1 and an integer
</span>
</div>
</div>
<div class="form-group">
<div class="col-sm-2">
<button type="submit" class="btn btn-primary pull-right" ng-click="addAlert(form)" ng-disabled="alertForm.$invalid">
Save
</button>
</div>
</div>
</form>
当我在cautionMultiplier
框中输入任何非整数(即&#39; a&#39;)时,验证消息The value is not a valid integer
不会触发。
我做错了什么?
答案 0 :(得分:0)
只有在“必需”键出错时才会显示此错误消息:
ng-show="alertForm.cautionMultiplier.$error.required && alertForm.amount.$dirty"
将required
替换为number
。
答案 1 :(得分:0)
固定
我的问题是:alertForm.amount.$dirty
应该是alertForm.cautionMultiplier.$dirty