Please tell me if there is any other way to do this using v-date-picker. I just want the user to be able to select the year and month and then the date picker menu should close.
This is my html as an example, but I don't mind using different code as long as it still uses v-date-picker.
<v-menu v-model='monthMenu' :close-on-content-click='false' :nudge-right='40' transition='scale-transition' offset-y min-width='290px'> <template v-slot:activator='{ on, attrs }'> <v-text-field v-model='txtMonth' label='Month' prepend-icon='mdi-calendar' readonly v-bind='attrs' v-on='on' ></v-text-field> </template> <v-date-picker v-model='month' @change='datePicked' color='primary' scrollable ></v-date-picker> </v-menu>
ts, datePicked method has what I tried but didn't work
export default Vue.extend({ data() { return { monthMenu: false, month: new Date(new Date().getFullYear(), new Date().getMonth()).toISOString() .substr(0, 10), }; }, computed: { txtMonth(): string { const [year, month, day] = this.month.split('-'); return `${year}/${month}/${day}`; }, }, methods: { datePicked(log: any) { /* eslint-disable */ console.log('here2'); // const el = document.getElementsByClassName('v-date-picker-table--month') as unknown as HTMLElement; const acc = document.getElementsByClassName('v-date-picker-table--month'); let i; for (i = 0; i < acc.length; i++) { acc[i].addEventLis tener("click",function() { console.log('here'); // this.monthMenu = false }); } }, }, });
After spending a few hours on this requirement, I was able to implement it. You can turn off an open date picker mode by observing the month model value. Additionally, the
element is assigned atype
attribute with a value ofmonth
.Live Demo: