在 Ionic 中完成输入字段后如何验证以显示错误
How to validate to show error after input field complete in Ionic
*您好,
我是 angularJS.Now 的新手 我试图在输入完整文本后显示错误。但是我在开始输入文本时收到错误消息 Input.Please 帮助找到解决方案。感谢 advance.My代码是
<label class="item item-input" class="form-group" data-ng-class=" {'has-error':!myForm.zipCode.$valid}">
<span class="input-label">Zip Code</span>
<input type="text" ng-model="currentUser.zipCode" class="form-control" id="zipCode" name="zipCode" ng-pattern="/^(\d{5}-\d{4}|\d{5})$/" required="" >
</label>
<span ng-show="myForm.zipCode.$error.pattern" class="help-block" style="color:red;" role="alert">Please enter proper Zip Code</span>*
<form role="form" name="myForm" novalidate="">
<div class="form-group" data-ng-class="{'has-error':!myForm.zipCode.$valid && myForm.zipCode.$dirty}">
<label for="zipCode">Zip Code</label>
<input type="text" class="form-control" id="zipCode" name="zipCode" ng-model="auth.zip" ng-pattern="/^(\d{5}-\d{4}|\d{5})$/" required="">
</div>
<div data-ng-show="myForm.zipCode.$error.required && myForm.zipCode.$dirty " class="alert alert-danger alert- dismissible" role="alert">
<strong>Zip Code is Required</strong>
</div>
<div data-ng-show="myForm.zipCode.$error.pattern" class="alert alert-danger alert-dismissible" role="alert">
<strong>Please enter proper Zip Code</strong>
</div>
</form>
第一次加载表单时使用$dirty
。它会 false
所以你的工作已经完成
*您好, 我是 angularJS.Now 的新手 我试图在输入完整文本后显示错误。但是我在开始输入文本时收到错误消息 Input.Please 帮助找到解决方案。感谢 advance.My代码是
<label class="item item-input" class="form-group" data-ng-class=" {'has-error':!myForm.zipCode.$valid}">
<span class="input-label">Zip Code</span>
<input type="text" ng-model="currentUser.zipCode" class="form-control" id="zipCode" name="zipCode" ng-pattern="/^(\d{5}-\d{4}|\d{5})$/" required="" >
</label>
<span ng-show="myForm.zipCode.$error.pattern" class="help-block" style="color:red;" role="alert">Please enter proper Zip Code</span>*
<form role="form" name="myForm" novalidate="">
<div class="form-group" data-ng-class="{'has-error':!myForm.zipCode.$valid && myForm.zipCode.$dirty}">
<label for="zipCode">Zip Code</label>
<input type="text" class="form-control" id="zipCode" name="zipCode" ng-model="auth.zip" ng-pattern="/^(\d{5}-\d{4}|\d{5})$/" required="">
</div>
<div data-ng-show="myForm.zipCode.$error.required && myForm.zipCode.$dirty " class="alert alert-danger alert- dismissible" role="alert">
<strong>Zip Code is Required</strong>
</div>
<div data-ng-show="myForm.zipCode.$error.pattern" class="alert alert-danger alert-dismissible" role="alert">
<strong>Please enter proper Zip Code</strong>
</div>
</form>
第一次加载表单时使用$dirty
。它会 false
所以你的工作已经完成