Datepicker

Vue Bootstrap 5 Datepicker

Date picker is a component that adds the function of selecting date without the necessity of using a custom code.

Note: Read the API tab to find all available options and advanced customization


Basic example

        
            
            <template>
              <MDBDatepicker v-model="picker1" label="Select a date" />
            </template>
          
        
    
        
            
            <script>
              import { ref } from "vue";
              import { MDBDatepicker } from "mdb-vue-ui-kit";
              export default {
                components: {
                  MDBDatepicker
                },
                setup() {
                  const picker1 = ref("");
                  return {
                    picker1
                  };
                }
              };
            </script>
          
        
    

Inline version

        
            
            <template>
              <MDBDatepicker v-model="picker2" inline label="Select a date" />
            </template>
          
        
    
        
            
            <script>
              import { ref } from "vue";
              import { MDBDatepicker } from "mdb-vue-ui-kit";
              export default {
                components: {
                  MDBDatepicker
                },
                setup() {
                  const picker2 = ref("");
                  return {
                    picker2
                  };
                }
              };
            </script>
          
        
    

Translations

The picker can be customized to add support for internationalization. Modify the component props to add translations.

        
            
            <template>
              <MDBDatepicker
                v-model="picker3"
                label="Select a date"
                title="Datum auswählen"
                :monthsFull="[
                  'Januar',
                  'Februar',
                  'März',
                  'April',
                  'Mai',
                  'Juni',
                  'Juli',
                  'August',
                  'September',
                  'Oktober',
                  'November',
                  'Dezember'
                ]"
                :monthsShort="[
                  'Jan',
                  'Feb',
                  'Mär',
                  'Apr',
                  'Mai',
                  'Jun',
                  'Jul',
                  'Aug',
                  'Sep',
                  'Okt',
                  'Nov',
                  'Dez'
                ]"
                :weekdaysFull="[
                  'Sonntag',
                  'Montag',
                  'Dienstag',
                  'Mittwoch',
                  'Donnerstag',
                  'Freitag',
                  'Samstag'
                ]"
                :weekdaysShort="['Son', 'Mon', 'Die', 'Mit', 'Don', 'Fre', 'Sam']"
                :weekdaysNarrow="['S', 'M', 'D', 'M', 'D', 'F', 'S']"
                okBtnText="Ok"
                clearBtnText="Klar"
                cancelBtnText="Schließen"
              />
            </template>
          
        
    
        
            
            <script>
              import { ref } from "vue";
              import { MDBDatepicker } from "mdb-vue-ui-kit";
              export default {
                components: {
                  MDBDatepicker
                },
                setup() {
                  const picker3 = ref("");
                  return {
                    picker3
                  };
                }
              };
            </script>
          
        
    

Formats

Use format property to display date in a human-friendly format.

        
            
            <template>
              <MDBDatepicker
                v-model="picker4"
                label="Select a date"
                format="DD, MMM, YYYY"
                placeholder="DD, MMM, YYYY"
              />
            </template>
          
        
    
        
            
            <script>
              import { ref } from "vue";
              import { MDBDatepicker } from "mdb-vue-ui-kit";
              export default {
                components: {
                  MDBDatepicker
                },
                setup() {
                  const picker4 = ref("");
                  return {
                    picker4
                  };
                }
              };
            </script>
          
        
    

Formatting rules

The following rules can be used to format any date:

Rule Description Result
D Day of the month 1 – 31
DD Day of the month with a leading zero 01 – 31
ddd Day of the week in short form Sun – Sat
dddd Day of the week in full form Sunday – Saturday
M Month of the year 1 – 12
MM Month of the year with a leading zero 01 – 12
MMM Month name in short form Jan – Dec
MMMM Month name in full form January – December
YY Year in short form * 00 – 99
YYYY Year in full form 2000 – 2999

Date limits

Set the minimum and maximum selectable dates with the min and max props.

        
            
            <template>
              <MDBDatepicker
                v-model="picker5"
                label="Select a date"
                min="10/06/2020"
                max="10/06/2022"
              />
            </template>
          
        
    
        
            
            <script>
              import { ref } from "vue";
              import { MDBDatepicker } from "mdb-vue-ui-kit";
              export default {
                components: {
                  MDBDatepicker
                },
                setup() {
                  const picker5 = ref("");
                  return {
                    picker5
                  };
                }
              };
            </script>
          
        
    

Disabled dates

The fitler option accept function in which you can specify conditions for date filtering. A result of true indicates that the date should be valid and a result of false indicates that it should be disabled. In the following example all saturdays and sundays will be disabled.

        
            
            <template>
              <MDBDatepicker
                v-model="picker6"
                label="Select a date"
                :filter="date => date.day() === 0 || date.day() === 6"
              />
            </template>
          
        
    
        
            
            <script>
              import { ref } from "vue";
              import { MDBDatepicker } from "mdb-vue-ui-kit";
              export default {
                components: {
                  MDBDatepicker
                },
                setup() {
                  const picker6 = ref("");
                  return {
                    picker6
                  };
                }
              };
            </script>
          
        
    

Input toggle

Add inputToggle property to enable toggling on input click. It is also possible to set toggleButton option to false to remove the toggle button.

        
            
            <template>
              <MDBDatepicker
                v-model="picker7"
                label="Select a date"
                inputToggle
                :toggleButton="false"
              />
            </template>
          
        
    
        
            
            <script>
              import { ref } from "vue";
              import { MDBDatepicker } from "mdb-vue-ui-kit";
              export default {
                components: {
                  MDBDatepicker
                },
                setup() {
                  const picker7 = ref("");
                  return {
                    picker7
                  };
                }
              };
            </script>
          
        
    

Custom toggle icon

You can customize the toggle icon by adding a toggleIcon alternative string template to the component.

        
            
            <template>
              <MDBDatepicker
                v-model="picker8"
                label="Select a date"
                toggleIcon="<i class='fas fa-calendar datepicker-toggle-icon'></i>"
              />
            </template>
          
        
    
        
            
            <script>
              import { ref } from "vue";
              import { MDBDatepicker } from "mdb-vue-ui-kit";
              export default {
                components: {
                  MDBDatepicker
                },
                setup() {
                  const picker8 = ref("");
                  return {
                    picker8
                  };
                }
              };
            </script>
          
        
    

Accessibility

We added proper aria attributes to the datepicker controls to make the component accessible. It's possible to change the values of those attributes by modyfing the component properties:

        
            
            okBtnLabel: 'Confirm selection',
            clearBtnLabel: 'Clear selection',
            cancelBtnLabel: 'Cancel selection',
            nextMonthLabel: 'Next month',
            prevMonthLabel: 'Previous month',
            nextYearLabel: 'Next year',
            prevYearLabel: 'Previous year',
            nextMultiYearLabel: 'Next 24 years',
            prevMultiYearLabel: 'Previous 24 years',
            switchToMultiYearViewLabel: 'Choose year and month',
            switchToDayViewLabel: 'Choose date',
          
        
    

Datepicker - API


Import

        
            
          <script>
            import {
              MDBDatepicker
            } from 'mdb-vue-ui-kit';
          </script>
        
        
    

Properties

Name Type Default Description
cancelBtnLabel String 'Cancel selection' Changes cancel button aria label
cancelBtnText String 'Cancel' Changes cancel button text
clearBtnLabel String 'Clear selection' Changes clear button aria label
clearBtnText String 'Clear' Changes clear button text
filter Function () => false Enables filtering
format String 'DD/MM/YYYY' Changes date format displayed in input
inline Boolean false Changes datepicker display mode to inline (dropdown)
inputToggle Boolean false Enables input toggling
max Date - Changes max available date
min Date - Changes min available date
monthsFull Array [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December', ] Changes array of months full names
monthsShort Array ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] Changes array of months short names
nextMonthLabel String 'Next month' Changes next button aria label in days view
nextMultiYearLabel String 'Next 24 years' Changes next button aria label in years view
nextYearLabel String 'Next year' Changes next button aria label in months view
okBtnLabel String 'Confirm selection' Changes ok button aria label
okBtnText String 'Ok' Changes ok button text
prevMonthLabel String 'Previous month' Changes previous button aria label in days view
prevMultiYearLabel String 'Previous 24 years' Changes previous button aria label in years view
prevYearLabel String 'Previous year' Changes previous button aria label in months view
startDate String '' Changes default date to which datepicker will navigate
startDay Number 0 Changes default start day (0 for Sunday, 1 for Monday)
switchToDayViewLabel String 'Choose date' Changes view change button aria label in years view
switchToMultiYearViewLabel String 'Choose year and month' Changes view change button aria label in days view
title String 'Select date' Changes datepicker title
toggleButton Boolean false Enables toggle button
toggleIcon String "<i class='far fa-calendar datepicker-toggle-icon'></i>" Defines toggle icon template
weekdaysFull Array ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] Changes array of weekdays full names
weekdaysNarrow Array ['S', 'M', 'T', 'W', 'T', 'F', 'S'] Changes array of weekdays narrow names
weekdaysShort Array ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'] Changes array of weekdays short names
view String 'day' Changes default datepicker view (day/year/month)
v-model String '' Returns current picked date

Methods

Name Description Example
open Manually opens a datepicker pickerRef.open()
close Manually closes a datepicker pickerRef.close()
        
            
              <template>
                <MDBDatepicker v-model="picker1" ref="pickerRef" />
                <MDBBtn @click.stop="$refs.pickerRef.open()" color="primary">
                  Open
                </MDBBtn>
              </template>
            
        
    

Events

Name Description
close This event fires immediately when the datepicker is closed.
open This event fires immediately when the datepicker is opened.
update:modelValue This event fires immediately when the datepicker value is changed.
update:isValid This event fires immediately when the datepicker valid value is changed
update:isValidated This event fires immediately when the datepicker validation value is changed
        
            
              <template>
                <MDBDatepicker v-model="picker1" @close="doSomething" />
              </template>