How to disable form validation for ng-click?

I have a form where certain inputs have a โ€œrequiredโ€ attribute. I also have a button that adds form fields when clicked, but it always triggers a form validation message when the required fields are not populated. I only need a form confirmation to run for ng-submit, not ng-click. Is it possible?

+5
source share
3 answers

If you look at the W3C spec, it would seem like an obvious attempt to mark your button elements with type = 'button' when you don't want them to be sent.

In particular, it should be noted that he says

A button element without a specified type attribute is the same thing as a button element with a type attribute set to "send"

+17
source

Use novalidate for your form:

 <form name="aForm" novalidate> 

or use the ng form instead:

 <div ng-form name="aForm"> 

Check out this link for more information on form validation in AngularJS.

0
source

when you do not want to send to a specific button, then define type = "button". it will work 100%

0
source

Source: https://habr.com/ru/post/1206855/


All Articles