Angular 4.0.0 novalidate attribute

After switching to angular 4, there was a strange problem with my template driven form. My requiredattr at the entrance seems to be broken. I assume that the default attribute novalidate. But I need some html5 checks. I tried novalidate="false", but did not succeed. Is there a way to activate verification? Now it seems that using reactive forms with it Validators.requiredis the only way.

Thanks!

My HTML code snippet:

<form (submit)="savePhone(phone);" novalidate="false">
<h3> </h3>
<md-input-container>
    <input mdInput placeholder=" "
           onlyNumber="true" name="number"
           [(ngModel)]="phone.number" required>
</md-input-container>
<md-select placeholder=" " (ngModel)="phone.source" name="source">
    <md-option *ngFor="let source of sources" [value]="source">
        {{ source }}
    </md-option>
</md-select>
<textarea name="comment" placeholder=" "
          [(ngModel)]="phone.comment" name="comment">
</textarea>
<div layout="row" layout-align="end">
    <button class="button button--success" type="submit">
        
    </button>
</div>

+6
source share
1 answer

To enable HTML5 validation, use

<form (submit)="savePhone(phone);" ngNativeValidate>

See also NgNoValidate Source on GitHub

+14

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


All Articles