I'm using ngx-botstrap BsDatepickerModule for my application form and I have a requirement to pick only a month. Does anyone know where I can find a solution? This issue has been raised almost a year ago and looks like it is highly demanded, so I conceal a hope to get an answer. This is what I would like to see after clicking a date selector button:
I managed to solve this using the same bsDatepicker, with minimal effort
Component template:
<form class="container">
<input [(ngModel)]="modelDate" autocomplete="off" class="form-control" name="date" bsDatepicker [bsConfig]="{dateInputFormat: 'MM/YYYY'}" (onShown)="onOpenCalendar($event)">
Result: <p>{{modelDate}}</p>
</form>
Component code sample:
onOpenCalendar(container) {
container.monthSelectHandler = (event: any): void => {
container._store.dispatch(container._actions.select(event.date));
};
container.setViewMode('month');
}
Check working sample here https://stackblitz.com/edit/ngx-datepicker-month-picker-poc
Just place minMode:'month'
in bsConfig, this worked perfectly fine for me.
[bsConfig]="{ minMode:'month', adaptivePosition: true, dateInputFormat: 'MMMM YYYY' }"
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