Javascript 单击angularjs中的提交表单时如何删除“请填写此字段”弹出但其他验证应该有效
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33014889/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to remove "please fill out this field" pop up when click on submit form in angularjs but other validations should work
提问by Priyanka Maurya
I want to remove the "please fill out this field" pop-up as validation and normal validations which are declared should display.
我想删除“请填写此字段”弹出窗口作为验证和声明应该显示的正常验证。
Html:
网址:
<div class="panel-body">
<form role="form" id="createForm" v name="createForm" ng-submit="createAdminGroup(adminGroupData)">
<div class="form-group" ng-class="{ 'has-error' : createForm.firstName.$invalid && !createForm.firstName.$pristine}">
<label class="label1">First Name</label>
<input name="firstName" id="firstName" class="form-control" placeholder="First Name" name="firstName" type="text" ng-model="adminGroupData.firstName " required/>
<span style="color:red" ng-show="createForm.firstName.$invalid && !createForm.firstName.$pristine">Please enter first name</span>
</div>
<div class="form-group">
<label class="label1">Last Name </label>
<input name="lastName" id="lastName" class="form-control" placeholder="Last Name" name="lastNmae" type="text" ng-model="adminGroupData.lastName" />
</div>
<div class="form-group">
<label class="label1"> Email Id </label>
<input type="email" name="email" id="email" class="form-control" placeholder="[email protected]" value=""ng-model="adminGroupData.email"/>
</div>
<div class="form-group">
<label class="label1"> Password </label>
<input name="password" id="password" class="form-control" placeholder="password" value="" ng-model="adminGroupData.password" />
</div>
<button name="submit" type="submit" class="btn btn-success" id="" ng-disabled="userForm.$invalid">Save</button>
<button class="btn btn-default" id="cancel" type="button" onclick='handleCancelCreateAdmin()'> Back </button>
</form>
</div>
回答by Guruprasad Rao
Add novalidate
attribute to your form
to disable browser default validation
将novalidate
属性添加到您的form
以禁用浏览器默认验证
For Ex
对于前
<form role="form" novalidate id="createForm" v name="createForm" ng-submit="createAdminGroup(adminGroupData)">
回答by Geraldo Novais
Add the attribute formnovalidateinside your submit button:
在提交按钮中添加属性formnovalidate:
Example:
例子:
<button name="submit" type="submit" formnovalidate class="btn btn-success">Save</button>
This will disable only the browser form validation. You still have the validation from your AngularJS code.
这将仅禁用浏览器表单验证。您仍然可以通过 AngularJS 代码进行验证。
You can see the W3C specification here
您可以在此处查看 W3C 规范
I had the same problem a few days ago and that's how I managed to solve
几天前我遇到了同样的问题,这就是我设法解决的方法
回答by guy
I just tried this and it worked:
我刚试过这个,它奏效了:
oninvalid="this.setCustomValidity(' ')" oninput="this.setCustomValidity('')" >
oninvalid="this.setCustomValidity(' ')" oninput="this.setCustomValidity('')" >
I have add a space between the two single quotes.
我在两个单引号之间添加了一个空格。
Since i added a bootstrap tooltip on my input fields and required, the invalid input comes to focus and displays the tooltip value.
由于我在输入字段上添加了引导工具提示并且是必需的,因此无效的输入会成为焦点并显示工具提示值。
It was simpler than I thought it would be.
这比我想象的要简单。