A simple Vue.js datepicker component. Supports disabling of dates, inline mode, translations

Last update: Jun 28, 2022

Datepicker

Travis Build Version Coveralls github Downloads

A datepicker Vue component. Compatible with Vue 2.x

NB. Vue 1.x was supported up to version v0.9.9. If you want to use this component with Vue 1.x you can install with npm install [email protected]

Demo

To view a demo online: https://codesandbox.io/s/mpklq49wp

To view demo examples locally clone the repo and run npm install && npm run serve

Install

npm install vuejs-datepicker --save
import Datepicker from 'vuejs-datepicker';

export default {
  // ...
  components: {
    Datepicker
  }
  // ...
}

Or use directly from a CDN

<div id="app">
  <vuejs-datepicker></vuejs-datepicker>
</div>
<script src="https://unpkg.com/vue"></script>
<script src="https://unpkg.com/vuejs-datepicker"></script>
<script>
const app = new Vue({
  el: '#app',
  components: {
  	vuejsDatepicker
  }
})
</script>

<!-- French language example -->
<div id="app">
  <vuejs-datepicker :language="fr"></vuejs-datepicker>
</div>
<script src="https://unpkg.com/vue"></script>
<script src="https://unpkg.com/vuejs-datepicker"></script>
<script src="https://unpkg.com/vuejs-datepicker/dist/locale/translations/fr.js"></script>
<script>
const app = new Vue({
  el: '#app',
  data() {
    return {
      fr: vdp_translation_fr.js
    }
  },
  components: {
  	vuejsDatepicker
  }
})
</script>

Usage

<datepicker></datepicker>

value prop if passed should be a Date object

<script>
var state = {
  date: new Date(2016, 9,  16)
}
</script>
<datepicker :value="state.date"></datepicker>

support name attribute for normal html form submission

<datepicker :value="state.date" name="uniquename"></datepicker>

Using v-model

<datepicker v-model="state.date" name="uniquename"></datepicker>

Emits events

<datepicker @selected="doSomethingInParentComponentFunction" @opened="datepickerOpenedFunction" @closed="datepickerClosedFunction">

Inline always open version

<datepicker :inline="true"></datepicker>

Available props

Prop Type Default Description
value Date|String Date value of the datepicker
name String Input name property
id String Input id
format String|Function dd MMM yyyy Date formatting string or function
full-month-name Boolean false To show the full month name
language Object en Translation for days and months
disabled-dates Object See below for configuration
placeholder String Input placeholder text
inline Boolean To show the datepicker always open
calendar-class String|Object CSS class applied to the calendar el
input-class String|Object CSS class applied to the input el
wrapper-class String|Object CSS class applied to the outer div
monday-first Boolean false To start the week on Monday
clear-button Boolean false Show an icon for clearing the date
clear-button-icon String Use icon for button (ex: fa fa-times)
calendar-button Boolean false Show an icon that that can be clicked
calendar-button-icon String Use icon for button (ex: fa fa-calendar)
calendar-button-icon-content String Use for material-icons (ex: event)
day-cell-content Function Use to render custom content in day cell
bootstrap-styling Boolean false Output bootstrap v4 styling classes.
initial-view String minimumView If set, open on that view
disabled Boolean false If true, disable Datepicker on screen
required Boolean false Sets html required attribute on input
typeable Boolean false If true, allow the user to type the date
use-utc Boolean false use UTC for time calculations
open-date Date|String If set, open on that date
minimum-view String 'day' If set, lower-level views won't show
maximum-view String 'year' If set, higher-level views won't show

Events

These events are emitted on actions in the datepicker

Event Output Description
opened The picker is opened
closed The picker is closed
selected Date|null A date has been selected
selectedDisabled Object A disabled date has been selected
input Date|null Input value has been modified
cleared Selected date has been cleared
changedMonth Object Month page has been changed
changedYear Object Year page has been changed
changedDecade Object Decade page has been changed

Date formatting

String formatter

NB. This is not very robust at all - use at your own risk! Needs a better implementation.

Token Desc Example
d day 1
dd 0 prefixed day 01
D abbr day Mon
su date suffix st, nd, rd
M month number (1 based) 1 (for Jan)
MM 0 prefixed month 01
MMM abbreviated month name Jan
MMMM month name January
yy two digit year 16
yyyy four digit year 2016

Function formatter

Delegates date formatting to provided function. Function will be called with date and it has to return formated date as a string. This allow us to use moment, date-fns, globalize or any other library to format date.

<script>
  methods: {
    customFormatter(date) {
      return moment(date).format('MMMM Do YYYY, h:mm:ss a');
    }
  }
</script>
<datepicker :format="customFormatter"></datepicker>

Disabled Dates

Dates can be disabled in a number of ways.

<script>
var state = {
  disabledDates: {
    to: new Date(2016, 0, 5), // Disable all dates up to specific date
    from: new Date(2016, 0, 26), // Disable all dates after specific date
    days: [6, 0], // Disable Saturday's and Sunday's
    daysOfMonth: [29, 30, 31], // Disable 29th, 30th and 31st of each month
    dates: [ // Disable an array of dates
      new Date(2016, 9, 16),
      new Date(2016, 9, 17),
      new Date(2016, 9, 18)
    ],
    ranges: [{ // Disable dates in given ranges (exclusive).
      from: new Date(2016, 11, 25),
      to: new Date(2016, 11, 30)
    }, {
      from: new Date(2017, 1, 12),
      to: new Date(2017, 2, 25)
    }],
    // a custom function that returns true if the date is disabled
    // this can be used for wiring you own logic to disable a date if none
    // of the above conditions serve your purpose
    // this function should accept a date and return true if is disabled
    customPredictor: function(date) {
      // disables the date if it is a multiple of 5
      if(date.getDate() % 5 == 0){
        return true
      }
    }
  }
}
</script>
<datepicker :disabled-dates="state.disabledDates"></datepicker>

Highlighted Dates

Dates can be highlighted (e.g. for marking an appointment) in a number of ways. Important: By default disabled dates are ignored, to highlight disabled dates set the includeDisabled property to true. Note: Both to and from properties are required to define a range of dates to highlight.

<script>
var state = {
  highlighted: {
    to: new Date(2016, 0, 5), // Highlight all dates up to specific date
    from: new Date(2016, 0, 26), // Highlight all dates after specific date
    days: [6, 0], // Highlight Saturday's and Sunday's
    daysOfMonth: [15, 20, 31], // Highlight 15th, 20th and 31st of each month
    dates: [ // Highlight an array of dates
      new Date(2016, 9, 16),
      new Date(2016, 9, 17),
      new Date(2016, 9, 18)
    ],
    // a custom function that returns true of the date is highlighted
    // this can be used for wiring you own logic to highlight a date if none
    // of the above conditions serve your purpose
    // this function should accept a date and return true if is highlighted
    customPredictor: function(date) {
      // highlights the date if it is a multiple of 4
      if(date.getDate() % 4 == 0){
        return true
      }
    },
    includeDisabled: true // Highlight disabled dates
  }
}
</script>
<datepicker :highlighted="state.highlighted"></datepicker>

Slots

Slots will help you customize content. .

beforeCalendarHeader

Sometimes you need to show custom content before the calendar header. For such cases you can use the named slot beforeCalendarHeader.

An example would be to use bootstrap's input-group-prepend and input-group-append to show some custom text:

<datepicker :bootstrap-styling="true">
  <div slot="beforeCalendarHeader" class="calender-header">
    Choose a Date
  </div>
</datepicker>

afterDateInput

To implement some custom styling (for instance to add an animated placeholder) on DateInput, you might need to add elements as DateInput siblings. Slot named afterDateInput allows you to do that:

<datepicker>
  <span slot="afterDateInput" class="animated-placeholder">
    Choose a Date
  </span>
</datepicker>

Translations

Contributing guide - please use appropriate code from this list as the translation property.

  • Add your language as a module in the src/locale/translations dir.
  • Import and export it in the src/locale/index file
  • Add the Language to the available languages in the readme file.
  • Run npm run lint to make sure your code formatting is in line with the required code style.

How to apply language

Below script tag in component.

import {en, es} from 'vuejs-datepicker/dist/locale'

In component data.

data () {
    return {
      en: en,
      es: es
    }
}

html.

<datepicker :language="es"></datepicker>

Available languages

Abbr Language
af Afrikaans
ar Arabic
bg Bulgarian
bs Bosnian
ca Catalan
cs Czech
da Danish
de German
ee Estonian
el Greek
en English Default
es Spanish
fa Persian (Farsi)
fi Finnish
fo Faroese
fr French
ge Georgia
gl Galician
he Hebrew
hu Hungarian
hr Croatian
id Indonesian
is Icelandic
it Italian
ja Japanese
kk Kazakh
ko Korean
lb Luxembourgish
lt Lithuanian
lv Latvian
mk Macedonian
mn Mongolian
nbNO Norwegian Bokmål
nl Dutch
pl Polish
ptBR Portuguese-Brazil
ro Romanian
ru Russian
sk Slovak
slSI Slovenian
sv Swedish
sr Serbian (Latin)
srCyrl Serbian (Cyrl)
th Thai
tr Turkish
uk Ukrainian
ur Urdu
vi Vietnamese
zh Chinese
zhHK Chinese_HK

GitHub

https://github.com/charliekassel/vuejs-datepicker
Comments
  • 1. Setting typeable causes date value to go blank

    In version 1.2.0.

    Steps:

    1. Set the typeable property on picker
    2. Type a date into the picker, hit enter
    3. Use the calendar to enter a date into the picker
    4. Remove focus from the picker
    5. Notice that the picker input is now empty
    Reviewed by jeffmath at 2018-05-14 18:04
  • 2. add UTC full support

    Hello, I just noticed that this component always handle dates in localzone time, which is super inconvenient for absolute timestamps (UTC).

    Related issues: #23, #200, #313, #158, #118, etc

    So I added a non-breaking change to use UTC for time calculations. This option will be available via the prop use-utc

    Looking for your thoughts on this, Regards

    Reviewed by saintplay at 2018-03-15 20:18
  • 3. opened event is not work

    I want use opened event but didn't work. I can't find $emit('opened') in source. is it deleted?

    <vuejs-datepicker 
        slot="calender"
        slot-scope="props"
        :value="props.row.calender"
        :format="DatePickerFormat" 
        :language="ja"
        @opened="opened"
    ></vuejs-datepicker>
    
    
    Reviewed by skanehira at 2019-05-30 11:27
  • 4. Date in display is inaccurate

    Control:

                            <date-picker wrapper-class="has-icons-right"
                                input-class="input is-fullwidth{{ $errors->has('solution_date') ? ' is-danger' : '' }}"
                                name="solution_date"
                                format="yyyy-MM-dd"
                                v-model="solutionDate.date"></date-picker>
    

    Vue:

            solutionDate: {
                date: '2017-06-26'
            }
    

    Result in the UI: 2017-06-25

    What's going wrong?

    Reviewed by thc1967 at 2017-07-01 02:17
  • 5. Date is off by one day

    Hi!

    When i select the date, the output is off by 1 day. I assume it is a timezone issue however i am unable to find any solution. Here is the code:

    // In template <datepicker placeholder="Select date of shoot" :value.sync="formInputs.date" :format="format" name="date"

    // The data

    data() { return { formInputs: { date: new Date() }, format: 'd MMMM yyyy', } }

    And the screenshot:

    screen shot 2016-10-23 at 15 24 37

    I appreciate any help i can get :) Thank You!

    Reviewed by IstvanLovas at 2016-10-23 14:27
  • 6. Made full bootstrap styling possible + added calendar button

    Hi Charlie

    Thanks for the addon, we are using Bootstrap and are running into a few issues with the output of the component. Don't know if you are open for it, but these modifications makes bootstrap styling possible and adds the following features:

    • calendar button that activates the calendar
    • possibility to use icons (font awsome or glyphicons) in the buttons (calendar + clear)

    Usage would be:

    <datepicker format="D dsu MMM yyyy" :bootstrap-styling="true" :calendar-button="true" :clear-button="true" calendar-button-icon="fa fa-calendar" clear-button-icon="fa fa-times"></datepicker>

    or for glyphicon <datepicker format="D dsu MMM yyyy" :bootstrap-styling="true" :calendar-button="true" :clear-button="true" calendar-button-icon="glyphicon glyphicon-calendar" clear-button-icon="glyphicon glyphicon-remove"></datepicker>

    Cheers Adam

    Reviewed by websmurf at 2017-02-09 15:51
  • 7. Add readonly attribute to DateInput when it isn't typeable

    Adding this attribute removes the caret from the text input and improves the behaviour when the datepicker is used on your phone. The caret is still there for Firefox but it works for Chrome and Safari. On phones the readonly attribute stops the keyboard from appearing, which is annoying if the date picker isn't typeable.

    I also fixed a test that breaks when run in the eastern hemisphere and fixed some issues the linter identified.

    Reviewed by whossname at 2018-06-28 08:57
  • 8. Remove autocomplete on picker input

    Having autocomplete enabled on the picker input field blocks the display of the calendar. Please see the screenshot below. I've tested this in Chrome 66.0.3359.181 on Mac. Can you give us an option to disable autocomplete on the input field?

    screen shot 2018-05-31 at 01 54 20
    Reviewed by daniesy at 2018-05-30 22:56
  • 9. Writable inputs

    Hello,

    Sometimes is good to have inputs with both possibilities - click on a date in datepicker or write it manually. At this moment it's not possible, but what about in the future? Would you like to implement it?

    Reviewed by rootboard at 2017-12-17 21:29
  • 10. Fixed JavaScript standard violations to get rid of UglifyJs warnings

    While working with vue-webpack-template, which uses UglifyJs, I noticed the following warning:

    ERROR in static/js/vendor.96ef630218730bcf0b7c.js from UglifyJs SyntaxError: Unexpected token punc «(», expected punc «:» [./~/vuejs-datepicker/src/utils/DateUtils.js:8,0]

    Please take a look at my simple fix.

    Reviewed by kkomelin at 2016-08-08 05:13
  • 11. Date range functionality (A -> B)

    Had the need to select a range from date A -> date B, therefore I created a simple range prop.

    <datepicker :range="true" v-model="exampleRange" placeholder="Select range"></datepicker>

    This prop modifies some of the core functionality of the datepicker;

    • The picker is not closed on selection (like inline)
    • the picker lets user select two dates, one start and one end date.
    • When range prop is true, the picker's input emits an object instead of date: { "from": "2018-06-07T21:55:00.000Z", "to": "2018-06-15T21:55:00.000Z" }
    • Input field value is updated with two dates: 07 - 15 Jun (or 01 Jan - 01 Feb if the months are not the same)
    • :format prop formats both dates instead of default "selectedDate"
    • I modified the highlighted prop to allow for visualisation of the selected dates

    Todo; Would consider adding an @mouseover event that automatically highlights the dates? I will most likely implement this for myself in the future, but too lazy now as this suits my needs and deadline per now.

    Linter is ok but I'm not too familiar with unit testing, therefore I have not created nor runned any tests.

    Cheers for an awesome package 🥂

    Reviewed by kamerat at 2018-06-07 22:18
  • 12. max-view does not work

    I made a validation where user can only pick 7 dates from the start dates. The issue found when i put the start date one month-before this month, the icon "change month" needs to be clicked then the magic will happened which is so uncomfortable for me. Is it just a wrong script for me? kindly give me a proper documentation for this. this is my script: <datepicker v-model="metaFilter.end_date" v-validate="'required'" :minimum-view="dateFormatFilter(metaFilter.start_date)" :disabled-dates="takeSevenDay" type="date" :disabled="!metaFilter.start_date" name="end_date" />

    Sincerely

    Reviewed by egy2015 at 2022-05-26 03:51
  • 13. Bump tmpl from 1.0.4 to 1.0.5

    Bumps tmpl from 1.0.4 to 1.0.5.

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    Reviewed by dependabot[bot] at 2022-04-21 08:46
  • 14. Triggers "closed" event on clicking NOT on the datepicker.

    I wanted to make a custom validation with the datepicker inside it. The call of the closed event was not triggered at all. I followed the initial emit of the input blur event. Then I have found out that it closes the datepicker but does not emit the "closed" event because it does not pass true argument.

    Reviewed by Allemeshov at 2022-03-19 21:03
  • 15. Placeholder Takes a img src and not change by my placeholder

    i'm trying to add placeholder to the input but it takes a source of an image i don't no where is it comes from and i tired to try fix it please Help me Screenshot 2022-03-17 143627 Screenshot 2022-03-17 143603

    Reviewed by muojahead at 2022-03-17 12:36
VueJS component to select dates & time, including a range mode
VueJS component to select dates & time, including a range mode

VueCtkDateTimePicker A vue component for select dates (range mode available) & time This documentation is for v2.*. Find v1 documentation here Dark mo

Jun 22, 2022
A simple datepicker component based Vue 2.x: https://dwqs.github.io/v2-datepicker/

中文 README v2-datepicker A simple datepicker component based Vue 2.x. Installation npm: npm i --save v2-datepicker or yarn yarn add v2-datepicker Ge

Mar 8, 2021
This datepicker is a fully customisable Vue(v2.1.6) version of the material-ui datepicker
This datepicker is a fully customisable Vue(v2.1.6) version of the material-ui datepicker

vue-material-datepicker This datepicker is a fully customisable Vue(v2.1.6) version of the material-ui datepicker that fit all your projects. See belo

Dec 13, 2021
A VueJs datepicker with a similar look and functionality as the popular AirBnb datepicker.
A VueJs datepicker with a similar look and functionality as the popular AirBnb datepicker.

vue-airbnb-style-datepicker This is a VueJs version of the popular AirBnb datepicker. Supports range selection, disabling of dates, custom configurati

May 24, 2022
A Vue component of formatting dates using moment.

el-moment A Vue component of formatting dates using moment. Installation yarn add el-moment moment # npm i el-moment moment -S Usage import ElMoment f

May 25, 2022
Simple datepicker component for Vue 3

Simple datepicker component for Vue 3

Jun 6, 2022
A simple datepicker component for vue3.0
A simple datepicker component for vue3.0

A simple datepicker component for vue3.0

Mar 5, 2022
[Deprecated] calendar and datepicker component with material design for Vue.js
[Deprecated] calendar and datepicker component with material design for Vue.js

vue-datepicker calendar and datepicker component with material design for Vue.js Demo The demo page is HERE. Requirements Vue.js ^1.0.0 & ^2.0.0 momen

May 3, 2022
A vue component that provides datepicker for persian developers

vue persian datepicker This is a Jalali date picker component for Vue. این برنامه یک کامپوننت انتخاب تاریخ جلالی می باشد. Demo You can see a demo and

Jun 25, 2022
datepicker component for Vue 2.x
datepicker component for Vue 2.x

vue-date-picker datepicker component for Vue 2.x Screenshot Instllation $ npm install vue-date-picker --save Usage <template> <div class="demo">

Mar 24, 2022
Litepie Datepicker is a date range picker component for Vue.js and Tailwind CSS, dependent to day.js.
Litepie Datepicker is a date range picker component for Vue.js and Tailwind CSS, dependent to day.js.

Litepie Datepicker is a date range picker component for Vue.js and Tailwind CSS, dependent to day.js. Documentation For full documentation, visit lite

Jul 4, 2022
awesome, zero dependency, performant Vue datepicker component
awesome, zero dependency, performant Vue datepicker component

awesome, zero dependency, performant Vue datepicker component

Jun 12, 2022
Vue Datepicker Component
 Vue Datepicker Component

Datepicker Component For Vue

Jun 7, 2022
Datepicker component for Vue 3

The most complete date picker solution for Vue 3

May 12, 2022
Datepicker component for vue.js built with Tailwind CSS, and the day.js date library.
Datepicker component for vue.js built with Tailwind CSS, and the day.js date library.

Datepicker component for vue.js build with Tailwind CSS & dayjs date library

May 12, 2022
Vue draggable datepicker component
Vue draggable datepicker component

DraggableCal A datepicker Vue component. Compatible with Vue 2.x Demo Install Usage Available Languages Dev & Build Licence Thanks Demo To view a demo

Feb 5, 2022
A lightweight and easy to use Vue.js datepicker component
A lightweight and easy to use Vue.js datepicker component

A lightweight and easy to use Vue.js datepicker component (created for Vue 2.x)

Feb 5, 2019
A Beautiful Datepicker Component For Vue2
A Beautiful Datepicker Component For Vue2

vue-datepicker-local A Beautiful Datepicker Component For Vue2 Lightweight (less than 5kb minified and gzipped) Only dependencies Vue Beautiful! Demo

Jun 11, 2022
Vue component for selecting business hours. Supports days of the week, holidays and any other special business hours.

Vue Business Hours Vue component for setting business hours in an administration panel. Option to use a text <input> and <datalist> component with 'au

Apr 6, 2022