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>
To enable HTML5 validation use
<form (submit)="savePhone(phone);" ngNativeValidate>
See also NgNoValidate source at GitHub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With