如何禁用ng-click的表单验证?

时间:2021-12-24 03:57:42

I have a form where certain inputs have "required" attribute. I also have a button that adds form fields when clicked, but it always triggers the form validation message when the required fields are not filled out. I only want form validation to trigger for ng-submit and not ng-click. Is this possible?

我有一个表单,其中某些输入具有“必需”属性。我还有一个按钮,在单击时添加表单字段,但是当未填写必填字段时,它总是触发表单验证消息。我只想要表单验证来触发ng-submit而不是ng-click。这可能吗?

3 个解决方案

#1


17  

If you have a look at the W3C specification, it would seem like the obvious thing to try is to mark your button elements with type='button' when you don't want them to submit.

如果您看一下W3C规范,那么看起来很明显的事情就是当您不希望它们提交时,使用type ='button'标记您的按钮元素。

The thing to note in particular is where it says

值得注意的是它所说的地方

A button element with no type attribute specified represents the same thing as a button element with its type attribute set to "submit"

未指定type属性的button元素表示与其type属性设置为“submit”的button元素相同的元素

#2


0  

Use novalidate for your form:

对表单使用novalidate:

<form name="aForm" novalidate>

or use ng-form instead:

或者使用ng-form代替:

<div ng-form name="aForm">

Check this link for further info about form validation in AngularJS.

有关AngularJS中表单验证的更多信息,请查看此链接。

#3


0  

when you do not want submission on specific button then define type="button". it will 100% work

当您不想在特定按钮上提交时,请定义type =“button”。它将100%工作

#1


17  

If you have a look at the W3C specification, it would seem like the obvious thing to try is to mark your button elements with type='button' when you don't want them to submit.

如果您看一下W3C规范,那么看起来很明显的事情就是当您不希望它们提交时,使用type ='button'标记您的按钮元素。

The thing to note in particular is where it says

值得注意的是它所说的地方

A button element with no type attribute specified represents the same thing as a button element with its type attribute set to "submit"

未指定type属性的button元素表示与其type属性设置为“submit”的button元素相同的元素

#2


0  

Use novalidate for your form:

对表单使用novalidate:

<form name="aForm" novalidate>

or use ng-form instead:

或者使用ng-form代替:

<div ng-form name="aForm">

Check this link for further info about form validation in AngularJS.

有关AngularJS中表单验证的更多信息,请查看此链接。

#3


0  

when you do not want submission on specific button then define type="button". it will 100% work

当您不想在特定按钮上提交时,请定义type =“button”。它将100%工作