简体   繁体   中英

How to disable validation on a form in angular

I have a very long form with an enormous number of required fields, but I need to run tests by repeatedly submitting the form. It's not feasible for me to fill the entire form with dummy data every time I want to test submitting the form. I've been trying to create a global function that I can call from the console to disable form validation, or just set the form manually to be valid. I've even attempted to loop through every field and set them all manually to be valid, but I haven't gotten anything to work.

How to I override a form to disable its validation or set it to be valid, regardless of the content of the fields?

AFAIK there is no simple switch to turn off AngularJS validation. Actually most of the validation happens in the NgModelController and input directives - basically code in the input.js file. So, to get rid of the built-in validation you would have to re-develop code from this file (plus some others, like select).

Did you identify validation code as a performance bottleneck in your application?

1) You can add the novalidate attribute to your form tag. http://www.w3schools.com/tags/att_form_novalidate.asp

or

2) I use a pretty helpful extension for Chrome called Form Filler wich does exactly what you are asking for, ie: Fills all form inputs in a page with dummy data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM