Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Mar 14, 2025. It is now read-only.

Vue.js component for Flatpickr datetime picker 📆

License

NotificationsYou must be signed in to change notification settings

ankurk91/vue-flatpickr-component

Repository files navigation

downloadsjsdelivrnpm-versiongithub-tagbuildcodecovlicensets

Vue.js component forFlatpickr date-time picker.

Version matrix

Vue.js versionPackage versionBranch
2.x8.x8.x
3.x12.xmain

Features

  • Reactivev-model value
    • You can change flatpickr value programmatically
  • Reactiveconfig options
    • You can change config options dynamically
    • Component will watch for any changes and redraw itself
  • Can emit all possibleevents
  • Compatible withBootstrap or any other CSS framework
  • Supportswrapped mode
  • Works with validation libraries

Installation

npm install vue-flatpickr-component@^11

Usage

Minimal example

<template><flat-pickrv-model="date"/></template><scriptsetup>import{ref}from'vue';importflatPickrfrom'vue-flatpickr-component';import'flatpickr/dist/flatpickr.css';constdate=ref(null);</script>

Detailed example

Using Bootstrapinput group and Font Awesome icons

<template><section><divclass="form-group"><label>Select a date</label><divclass="input-group"><flat-pickrv-model="date":config="config"class="form-control"placeholder="Select date"name="date"/><divclass="input-group-append"><buttonclass="btn btn-default"type="button"title="Toggle"data-toggle><iclass="fa fa-calendar"/><spanaria-hidden="true"class="sr-only">Toggle</span></button><buttonclass="btn btn-default"type="button"title="Clear"data-clear><iclass="fa fa-times"/><spanaria-hidden="true"class="sr-only">Clear</span></button></div></div></div><pre>Selected date is - {{date}}</pre></section></template><scriptsetup>import{ref}from'vue';import'bootstrap/dist/css/bootstrap.css';// import this componentimportflatPickrfrom'vue-flatpickr-component';import'flatpickr/dist/flatpickr.css';// theme is optional// try more themes at - https://flatpickr.js.org/themes/import'flatpickr/dist/themes/material_blue.css';// localization is optionalimport{Hindi}from'flatpickr/dist/l10n/hi.js';constdate=ref('2022-10-28');// Read more at https://flatpickr.js.org/options/constconfig=ref({wrap:true,// set wrap to true only when using 'input-group'altFormat:'M j, Y',altInput:true,dateFormat:'Y-m-d',locale:Hindi,// locale for this instance only});</script>

Events

  • The component can emit all possible events, you can listen to them in your component
<flat-pickrv-model="date"@on-change="doSomethingOnChange"@on-close="doSomethingOnClose"/>
  • Event names has been converted to kebab-case.
  • You can still pass your callback methods in:config like original flatpickr do.

Available props

The component accepts these props:

AttributeTypeDefaultDescription
v-modelString / Date Object / Array / Timestamp / nullnullSet or Get date-picker value (required)
configObject{ wrap: false }Flatpickr configurationoptions
eventsArrayArray of sensibleeventsCustomise theevents to be emitted

Use in browser with CDN

<!-- Flatpickr related files --><linkhref="https://cdn.jsdelivr.net/npm/flatpickr@4/dist/flatpickr.min.css"rel="stylesheet"><scriptsrc="https://cdn.jsdelivr.net/npm/flatpickr@4/dist/flatpickr.min.js"></script><!-- Vue.js --><scriptsrc="https://cdn.jsdelivr.net/npm/vue@3.3"></script><!-- Lastly add this package --><scriptsrc="https://cdn.jsdelivr.net/npm/vue-flatpickr-component@11"></script><script>constapp=Vue.createApp({})app.component('flat-pickr',VueFlatpickr.default);app.mount("#app");</script>

Run examples on your localhost

  • Clone this repo
  • Make sure you have node-js>=20.11 andpnpm>=9.x pre-installed
  • Install dependenciespnpm install
  • Run webpack dev servernpm start
  • This should open the demo page in your default web browser

Testing

  • This package is usingJestandvue-test-utils for testing.
  • Tests can be found in__test__ folder.
  • Execute tests with this commandnpm test

Changelog

Please seeCHANGELOG for more information what has changed recently.

License

MIT License


[8]ページ先頭

©2009-2025 Movatter.jp