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

Overview

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
Issues
  • add UTC full support

    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

    opened by saintplay 22
  • Setting typeable causes date value to go blank

    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
    bug 
    opened by jeffmath 22
  • Date in display is inaccurate

    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?

    opened by thc1967 19
  • opened event is not work

    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>
    
    
    opened by skanehira 18
  • Date is off by one day

    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!

    opened by IstvanLovas 18
  • Made full bootstrap styling possible + added calendar button

    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

    opened by websmurf 16
  • Added a button to clear the selecte date.

    Added a button to clear the selecte date.

    I've added a button to clear a selected date. This should also close #64. Feel free to add some styling after merging :-)

    opened by mazedlx 15
  • Remove autocomplete on picker input

    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
    opened by daniesy 14
  • Add vi locale

    Add vi locale

    opened by imcvampire 14
  • Add readonly attribute to DateInput when it isn't typeable

    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.

    opened by whossname 14
  • only allow future dates to be picked

    only allow future dates to be picked

    Hi, I would like to set my date picker to only have future dates to be able to be selected, how can I go about doing this?

    Thanks

    opened by jbiddulph 0
  • Create uz.js

    Create uz.js

    Adding 'uz' Uzbekish language

    opened by akahon 0
  • Select range of dates

    Select range of dates

    Hi all.

    I am searching for date picker library which has inline option so I think this one would be perfect but I have a problem that I need select a range of dates (start - end). I have read the document and demos but it seems this library currently supports selecting single date only.

    Any idea ? Thanking you,

    opened by vanminhquangtri 0
  • Datepicker component display bad date when selected a date

    Datepicker component display bad date when selected a date

    Hi all,

    I've got a problem with vuejs-datepicker.

    I use it like that in my Vue.js app :

    <datepicker placeholder="Choisissez une date" :language="fr" v-on:selected="selectDay" :disabledDates="disabledFn">
    </datepicker>
    
    import {fr} from 'vuejs-datepicker/dist/locale'
    

    When I select a date, for example September 1st :

    capt1

    This is a next day which look selected (September 2) : capt2 capt3

    When a get the date in my function v-on:selected="selectDay", I get the correct selected date. So the problem is only in the displayer.

    Any idea ?

    Thanking you,

    Jonathan

    opened by jojolasticot 1
  • Uncaught (in promise) TypeError: Cannot read property '_c' of undefined

    Uncaught (in promise) TypeError: Cannot read property '_c' of undefined

    Hi, I am pretty new to Vue and I am struggling to get this to work. I get this error in the console.

    Uncaught (in promise) TypeError: Cannot read property '_c' of undefined
        at Proxy.__vue_render__$4 (vuejs-datepicker.esm.js?fa33:2264)
        at renderComponentRoot (runtime-core.esm-bundler.js?5c40:1168)
        at componentEffect (runtime-core.esm-bundler.js?5c40:5214)
        at reactiveEffect (reactivity.esm-bundler.js?a1e9:42)
        at effect (reactivity.esm-bundler.js?a1e9:17)
        at setupRenderEffect (runtime-core.esm-bundler.js?5c40:5167)
        at mountComponent (runtime-core.esm-bundler.js?5c40:5126)
        at processComponent (runtime-core.esm-bundler.js?5c40:5084)
        at patch (runtime-core.esm-bundler.js?5c40:4690)
        at mountChildren (runtime-core.esm-bundler.js?5c40:4874)
    

    The terminal does not give me an error, so I am not sure what I need to do. I am using Vue 3.

    opened by moonshark 2
  • chore : fixed month abbreviation on month only picker

    chore : fixed month abbreviation on month only picker

    Reference issues #713

    What does it fix?

    It fixes the month abbreviation issue, allows you to pass a prop if you want to see the full month name or not

    opened by ayemitibo 0
  • How do I test vuejs-datepicker using jest

    How do I test vuejs-datepicker using jest

    After clicking my input box which has vuejs-datepicker bound to it, I am unable to find any elements with the class .cell

    opened by simonjcarr 0
  • datepicker is not opening or focus is not getting set on tab click

    datepicker is not opening or focus is not getting set on tab click

    i am trying to set focus or open the date picker on tab click but is not getting opened

    opened by IXBalaji 0
  • allowedDates

    allowedDates

    Hi,

    Maybe I have overlooked something. Is it possible to disable everything on the calendar and only use 'allowedDates' in a way?

    Thanks!

    opened by duikb00t 1
Releases(v1.5.1)
  • v1.5.1(Jun 20, 2018)

    Update markup for bootstrap styling to support bootstrap v4. Add pre-commit package to run lint and tests. Emit change month from DatePicker Add invalid attribute for autocomplete to attempt to prevent autocompletion. - https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion

    Source code(tar.gz)
    Source code(zip)
  • v1.4.0(Jun 19, 2018)

  • v1.2.2(May 18, 2018)

  • v1.2.0(May 11, 2018)

    Changes the event that closes the calendar from document click to input blur - https://github.com/charliekassel/vuejs-datepicker/pull/485 Fix for allowing enter to be pressed in non type mode - https://github.com/charliekassel/vuejs-datepicker/issues/487

    Source code(tar.gz)
    Source code(zip)
  • v1.1.5(May 8, 2018)

  • v1.1.2(May 3, 2018)

  • v1.1.0(May 1, 2018)

    Feature: Typeable dates introduced in 1.0.0 are no longer enabled by default and need to be specifically configured with the typeable prop set to true.

    Source code(tar.gz)
    Source code(zip)
  • v1.0.4(Apr 28, 2018)

  • v1.0.3(Apr 27, 2018)

  • v1.0.2(Apr 27, 2018)

  • v1.0.1(Apr 27, 2018)

    Breaking changes:

    • disabled has been renamed to disabledDates
    • disabledPicker has been renamed to disabled
    • Languages need to be explicitly imported, en is included by default

    Additions:

    • Dates can now be typed into the input - readonly attribute has been removed
    • Build changes to use rollup instead webpack
    Source code(tar.gz)
    Source code(zip)
  • v0.9.0(Jul 10, 2017)

  • v0.7.0(Apr 10, 2017)

    Renames wrapping css classes to a more unique namespace. Will potentially break older integrations if the datepicker's classes are targeted outside of the component.

    Source code(tar.gz)
    Source code(zip)
Owner
Charlie Kassel
Charlie Kassel
A clean datepicker made with VueJs

vue-datepicker A datepicker Vue component. Compatible with Vue 2.x Demo Install Usage Props Events Date Formatting Translations Best Practices Demo To

Mathieu Stanowski 133 Oct 5, 2021
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

Pomy 91 Mar 8, 2021
Vue Datepicker Component

Datepicker Component For Vue

Hatice Edis 365 Oct 12, 2021
Simple datepicker component for Vue 3

Simple datepicker component for Vue 3

Ilya Borovitinov 62 Oct 15, 2021
Vue date range picker component

A responsive date range picker for Vue.js that displays the number of nights selected and allow several useful options like custom check-in/check-out

Krystal Campioni 706 Oct 13, 2021
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

Mikael Edebro 497 Oct 4, 2021
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

飞越 294 Jul 17, 2021
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

Dyon Software Development Group 99 Aug 29, 2021
awesome, zero dependency, performant Vue datepicker component

awesome, zero dependency, performant Vue datepicker component

mohammad S. 26 Oct 7, 2021
[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

Awe 706 Aug 12, 2021
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

Ken 155 Oct 13, 2021
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">

8788 100 Sep 30, 2021
Jalaali calendar and datepicker for vue.js 2

vue-jalaali-datepicker Jalaali calendar and datepicker for vue.js 2 Demo Requirements Vue.js ^2.0.0 moment-jalaali ^0.6.0 Installation npm $ npm insta

Peyman 15 Aug 29, 2021
Datepicker component for Vue 3

The most complete date picker solution for Vue 3

null 28 Oct 12, 2021
A simple datepicker component for vue3.0

A simple datepicker component for vue3.0

Lin Masahiro 29 Jul 14, 2021
A vue plugin to select jalali date and time

vue-persian-datetime-picker A vue plugin to select jalali date and time See documentation and demo at vue-persian-datetime-picker Installation browser

Mohamad Talkhabi 463 Oct 9, 2021
移动端操作的日期插件,可以选择开始及结束日期,通常用于旅游行业

vue-datepicker-mobile v2 中文版 Live Demo Props param description type default custom custom data.* [object, array] - endText text of end for selected st

Clear Aki 17 Apr 26, 2021
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

Ken 182 Sep 23, 2021
A vue plugin to select jalali date and time

vue3-persian-datetime-picker A vue plugin to select jalali date and time See documentation and demo at vue-persian-datetime-picker. If you are using v

Mohamad Talkhabi 16 Oct 11, 2021