ngb-datepicker

How to mark ngbDatepicker Valid in form even when no value is selected

流过昼夜 提交于 2019-12-04 03:52:04
问题 I'm making use of ng-bootstrap's ngbDatepicker in a Reactive Form in an Angular2 project, and the dates are optional, however ngbDatepicker always marks the form as Invalid unless a date is selected. Is there a way to exclude ngbDatepicker from the form validation, or to configure it so that it returns Valid whether it has a value set or not? 回答1: The issue was with how I was initializing the form values. I was setting the default values to empty strings where I should have been initializing

How to mark ngbDatepicker Valid in form even when no value is selected

会有一股神秘感。 提交于 2019-12-01 18:36:13
I'm making use of ng-bootstrap's ngbDatepicker in a Reactive Form in an Angular2 project, and the dates are optional, however ngbDatepicker always marks the form as Invalid unless a date is selected. Is there a way to exclude ngbDatepicker from the form validation, or to configure it so that it returns Valid whether it has a value set or not? The issue was with how I was initializing the form values. I was setting the default values to empty strings where I should have been initializing the dates to null. So I was doing this: replicantForm = this.fb.group({ name: ['', Validators.required],