提交表单时NG-要求不工作 [英] ng-required not working when submitting a form
本文介绍了提交表单时NG-要求不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在与所需属性的文本输入框下面的code,但是当我标签场外或提交表单,它不会从提交并通知用户该字段为停止形式必需的。
I have the following code in an input text box with the required attribute, but when I tab off of the field or submit the form, it doesn't stop the form from submitting and informing the user the field is required.
<div class="col-sm-8">
<input type="text" ng-required="true" class="form-control"
placeholder="Enter Total Amount" id="txtTotalAmount"
ng-model="formCtrl.AddCheckDeposit.TotalAmount" />
</div>
什么我需要做的,使所需的指令来工作?
What do I need to do to make the required directive to work?
推荐答案
有关,你应该解雇 NG-提交
事件,当表单有效
For that you should fire ng-submit
event when form is valid
ng-submit="myForm.$valid && submit()"
好像你也错过了你的输入字段名称
属性,也为展示你可以使用一个错误 NG-节目
/ NG的消息
指令
Seems like you have also missed the name
attribute on your input field, also for showing an error you could use ng-show
/ng-messages
directive
<form name="myForm" ng-submit="myForm.$valid && submit()">
<div class="col-sm-8">
<input type="text" ng-required="true" class="form-control" placeholder="Enter Total Amount" name="txtTotalAmount"
id="txtTotalAmount" ng-model="formCtrl.AddCheckDeposit.TotalAmount" />
<span ng-show="myForm.txtTotalAmount.$error.required">Required</span>
</div>
</form>
这篇关于提交表单时NG-要求不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文