Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular 4.0.0 novalidate attribute

After migrating to angular 4 a strange issue with my template-driven form has occured. My required attr on input seems to be broken. I suppose that has novalidate attribute by default. But I need some html5 validations. Tried novalidate="false" but had no success. Is there some way to enable validation? Now it seems using reactive forms with its Validators.required is the only way.

Thanks!

My HTML component 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>

like image 620
Mike Kovetsky Avatar asked Apr 07 '17 09:04

Mike Kovetsky


1 Answers

To enable HTML5 validation use

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

See also NgNoValidate source at GitHub

like image 148
Günter Zöchbauer Avatar answered Oct 05 '22 20:10

Günter Zöchbauer