Reputation: 121
I used a bootstrap Datepicker in my Angular 7 project. I put it as an input inside a form like this:
I want to clear all the form once a "clear" button is clicked. The form.reset() function didn't work with the datepicker input.
<div class="col-lg-8 form-group">
<input id="startDate" type="text" placeholder="From"
class="form-control" bsDatepicker
[bsConfig]="{ adaptivePosition: true, dateInputFormat:'YYYY-
MM-DD'}" [(ngModel)]="selectedStartDate"
(ngModelChange)="updateMyStartDate($event)" [ngModelOptions]="
{standalone: true}">
</div>
Do you have any idea what should I do to reset the datepicker input and empty them .
Upvotes: 4
Views: 6099
Reputation: 66
You have to reset input/ngModel value on clear button click.
Put below line after form.reset();
in your function
this.selectedStartDate.value = ' ';
(for example, https://stackblitz.com/edit/angular-nv5qts?file=app%2Fdatepicker-overview-example.ts)
Upvotes: 3