Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 - Basic form validation not working anymore

I have an angular 2 application which contains a basic form with inputs and basic html validation. Something like:

<form (onSubmit)="submit()">
  <input type="email" />
  <input type="submit" value="save" />
</form>

This worked about a week or two ago. Today, I was testing my application and noticed that it's completely ignoring any basic validation like type, pattern, max, min, etc. In this case, it should complain when you type in a value without the @ symbol. However, it isn't complaining anymore. You can type whatever you want in the input field.

Any idea how this could happen?

like image 278
Krikke93 Avatar asked Oct 18 '25 03:10

Krikke93


1 Answers

I was having this issue too. So I searched and found this.

Basically by default angular is adding something called novalidate. If you guys want to use browser's native form validation just add ngNativeValidate attribute:

<form ngNativeValidate></form>
like image 186
Iván Sánchez Avatar answered Oct 19 '25 16:10

Iván Sánchez