2
使用我已經添加了一個ngbDatePicker反應形式:ngBootstrap對角4的DatePicker總是需要
<input type="text"
id="business_incorp_date"
class="form-control"
formControlName="business_incorp_date"
ngbDatepicker
#incorporatedDatePicker="ngbDatepicker"
(click)="incorporatedDatePicker.toggle()"
readonly>
對於一個表單模型:
this.form = this.formBuilder.group({
id: [
0, [Validators.required]
],
// ... removed for brevity
business_type: [
'', [Validators.required]
],
business_incorp_date: [
'', [FormValidators.date] // <-- NOT REQUIRED BY MODEL
],
business_desc: [
'', [Validators.required]
]
// ...
});
但是,如果字段是空的它仍然ngInvalid爲ngbDateFormat
:
{ "ngbDate": { "invalid": { "year": null, "month": null, "day": null } } }
任何人都知道如何使DatePicker字段允許一個空字符串?
參見:https://github.com/ng-bootstrap/ng-bootstrap/issues/1582#issuecomment-304204567 –