我目前有一个网站页面,用户可以在其中插入GPS坐标和位置等字段。我编辑了在字段上放置验证器的页面,以检查它们的最大长度。目前的行为是,当长度超过阈值时,字段周围的边框变为红色,并在下面显示“太长!”的通知。
除了坐标字段外,这适用于所有字段。它们看起来完全一样,但是,当我加载页面时,字段下方的通知出现,输入框为空。然而,边界不是红色的。当我删除ng-maxlength参数时,坐标看起来应该是这样(值为:5.32706)。
<form class="form-horizontal" role="form" name="deviceForm">
<fieldset>
<legend class="text-left">GPS</legend>
<div class="form-group">
<label for="gps.latitude" class="col-sm-2 control-label">Latitude</label>
<div class="col-sm-10">
<input ng-model="device.gps.latitude" type="text" class="form-control" name="latitude" id="gps.latitude" placeholder="" ng-maxlength="15" >
<span class="formValidationError" ng-show="deviceForm.latitude.$error.maxlength">Too long!</span>
</div>
</div>
<div class="form-group">
<label for="container.city" class="col-sm-2 control-label">Place</label>
<div class="col-sm-10">
<input ng-model="device.container.city" type="text" class="form-control" name="city" id="container.city" placeholder="" ng-maxlength="255" >
<span class="formValidationError" ng-show="deviceForm.city.$error.maxlength">Too long!</span>
</div>
</div>
</fieldset>
</form>
请注意,使用城市变量,一切正常。
当我开始输入现在空的纬度字段时,通知消失(条形图已经是正常颜色)。当我超过限制时,条形变为红色并再次显示通知。
为什么通知会在页面加载时显示,为什么在添加ng-maxlength属性时值不显示?
编辑:我试图将输入类型更改为“数字”,但没有效果。