Giter Site home page Giter Site logo

ankurk91 / vue-flatpickr-component Goto Github PK

View Code? Open in Web Editor NEW
961.0 16.0 101.0 2.15 MB

Vue.js component for Flatpickr datetime picker :calendar:

Home Page: https://ankurk91.github.io/vue-flatpickr-component/

License: MIT License

JavaScript 29.83% TypeScript 70.17%
flatpickr datepicker-component vue vue-flatpickr datepicker timepicker

vue-flatpickr-component's Introduction

Vue FlatPickr Component

downloads jsdelivr npm-version github-tag build codecov license ts

Vue.js component for Flatpickr date-time picker.

Version matrix

Vue.js version Package version Branch
2.x 8.x 8.x
3.x 11.x main

Features

  • Reactive v-model value
    • You can change flatpickr value programmatically
  • Reactive config options
    • You can change config options dynamically
    • Component will watch for any changes and redraw itself
  • Can emit all possible events
  • Compatible with Bootstrap or any other CSS framework
  • Supports wrapped mode
  • Works with validation libraries

Installation

npm install vue-flatpickr-component@^11

Usage

Minimal example

<template>
    <flat-pickr v-model="date"/>
</template>

<script setup>
    import {ref} from 'vue';
    import flatPickr from 'vue-flatpickr-component';
    import 'flatpickr/dist/flatpickr.css';

    const date = ref(null);
</script>

Detailed example

Using Bootstrap input group and Font Awesome icons

<template>
    <section>
        <div class="form-group">
            <label>Select a date</label>
            <div class="input-group">
                <flat-pickr
                    v-model="date"
                    :config="config"
                    class="form-control"
                    placeholder="Select date"
                    name="date"/>
                <div class="input-group-append">
                    <button class="btn btn-default" type="button" title="Toggle" data-toggle>
                        <i class="fa fa-calendar"/>
                        <span aria-hidden="true" class="sr-only">Toggle</span>
                    </button>
                    <button class="btn btn-default" type="button" title="Clear" data-clear>
                        <i class="fa fa-times"/>
                        <span aria-hidden="true" class="sr-only">Clear</span>
                    </button>
                </div>
            </div>
        </div>
        <pre>Selected date is - {{date}}</pre>
    </section>
</template>

<script setup>
    import {ref} from 'vue';
    import 'bootstrap/dist/css/bootstrap.css';
    // import this component
    import flatPickr from '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 optional
    import {Hindi} from 'flatpickr/dist/l10n/hi.js';

    const date = ref('2022-10-28');

    // Read more at https://flatpickr.js.org/options/
    const config = 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-pickr v-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:

Attribute Type Default Description
v-model String / Date Object / Array / Timestamp / null null Set or Get date-picker value (required)
config Object { wrap: false } Flatpickr configuration options
events Array Array of sensible events Customise the events to be emitted

Use in browser with CDN

<!-- Flatpickr related files -->
<link href="https://cdn.jsdelivr.net/npm/flatpickr@4/dist/flatpickr.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/flatpickr@4/dist/flatpickr.min.js"></script>
<!-- Vue.js -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<!-- Lastly add this package -->
<script src="https://cdn.jsdelivr.net/npm/vue-flatpickr-component@11"></script>
<script>
    const app = 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 and pnpm >=8.x pre-installed
  • Install dependencies pnpm install
  • Run webpack dev server npm start
  • This should open the demo page in your default web browser

Testing

  • This package is using Jest and vue-test-utils for testing.
  • Tests can be found in __test__ folder.
  • Execute tests with this command npm test

Changelog

Please see CHANGELOG for more information what has changed recently.

License

MIT License

vue-flatpickr-component's People

Contributors

aethr avatar ankurk91 avatar atilacamurca avatar choowx avatar eklundkristoffer avatar famoser avatar karllinden avatar kf99916 avatar mimbrown avatar qonstrukt avatar silentscripter avatar slynet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vue-flatpickr-component's Issues

Support Server Side Rendering

[ x ] Feature request

Tell about your platform

  • vue-flatpickr-component: ^2.4.1
  • flatpickr: 3.0.6
  • NPM 5.0.3
  • Nuxt.js: 1.0.0-alpha.5

Current behavior

[Vue warn]: The client-side rendered virtual DOM tree is not matching server-rendered content. This is likely caused by incorrect HTML markup, for example nesting block-level elements inside <p>, or missing <tbody>. Bailing hydration and performing full client-side render.

Expected behavior
Fully support SSR

Minimal reproduction of the problem with instructions

import Vue from 'vue'
import flatPickr from 'vue-flatpickr-component';
import 'flatpickr/dist/flatpickr.css'
// Vue.use(flatPickr)
flat-pickr(v-model="date")

load livereload.js failed

I'm submitting a ... (check one with "x")

[ ] Bug report => search github for a similar issue or PR before submitting
[ ] Feature request
[x] Other, please describe

Tell about your platform

  • flatPickr version : 4.1.1
  • Vue.js version : 2.5.3
  • Browser name and version : Chrome 62.0.3202.94
  • This package version : 4.0.0

Current behavior
GET http://localhost:35729/livereload.js?snipver=1 net::ERR_CONNECTION_REFUSED

Expected behavior
GET http://localhost:35729/livereload.js?snipver=1 success

Minimal reproduction of the problem with instructions
When I loaded page, chrome console will show

GET http://localhost:35729/livereload.js?snipver=1 net::ERR_CONNECTION_REFUSED
2017-11-16 14 30 56 png 3

Inline date time issues with the time in multiple mode

I'm submitting a ... (check one with "x")

[#] Bug report => search github for a similar issue or PR before submitting
[ ] Feature request
[ ] Other, please describe

Tell about your platform

  • flatPickr version : 4.1.4
  • Vue.js version : 2.5.9
  • Browser name and version : Chrome 62
  • This package version : 5.0.0

Current behavior

If you inline flatpickr and enable the time and multi multiple mode, you will realize that it is not as intuitive changing the time and it the first chosen time (earliest date) is the one that will be reactive always.

bug

Expected behavior
the latest chosen date time should be reactive.

Minimal reproduction of the problem with instructions

https://jsfiddle.net/63kzdwLx/99/

I would truly appreciate any advice as how I can workaround this bug or any help on fixing it would be amazing!

Thanks so much for this great component.

Old vue-flatpickr and vue-flatpickr-component retrocompatibility question

I'm always use npm install vue-flatpickr but today I recive that message deprecated [email protected]: this package has been deprecated

So I found this vue-flatpickr-component and install it to replace older vue-flatpickr then I saw config parseDate options stop work, this event never more was fired, my config is:

  fpOptions: {
    minDate: '2018-01-01',
    maxDate: new Date(),
    locale: pt,
    // dateFormat: 'Y-m-d',
    altFormat: 'd/m/Y',
    altInput: true,
    allowInput: true,
    parseDate: function (e) {
      if (e.indexOf('/') > 0) {
        let parts = e.split('/');
        let ee = new Date(parseInt(parts[2], 10),
          parseInt(parts[1], 10) - 1,
          parseInt(parts[0], 10));
        return ee;
      }
      let parts = e.split('-');
      let ee = new Date(parseInt(parts[0], 10),
        parseInt(parts[1], 10) - 1,
        parseInt(parts[2], 10));
      return ee;
    },
    onReady: function (a, b, c) {
      Mask.bind(c.altInput, { value: '99/99/9999' });
      c.altInput.addEventListener('keyup', (e) => {
        if (c.altInput.value.length >= 10) {
          c.setDate(c.altInput.value);
          setTimeout(() => { c.close(); }, 300);
        }
      });
    }
  },

What is wrong?

[2.1.0] UglifyJs Unexpected token: operator (>) [./~/vue-flatpickr-component/src/index.js:4,0]

[X] Other : support

Hello,

I've integrated your component (thanks for it !) but src/index.js makes my production webpack build fail with this message

ERROR in vendor.9cd50ac0.js from UglifyJs
Unexpected token: operator (>) [./~/vue-flatpickr-component/src/index.js:4,0][vendor.9cd50ac0.js:9,147031]

Seems related to es6 syntax in file below, but I have no idea about a fix.

 install: (Vue, options) => {
    Vue.component('flat-pickr', component);
    require('flatpickr/dist/flatpickr.css');  

Any suggestion ?
Thx

Not able to change class name from form-control to uk-input

I'm submitting a ... (check one with "x")

[ ] Bug report => search github for a similar issue or PR before submitting
[ ] Feature request
[ ] Other, please describe

Tell about your platform

  • flatPickr version : 3.x.x
  • Vue.js version : 2.x.x
  • Browser name and version : Chrome|Firefox|Safari x.x.x
  • This package version : x.x.x

Current behavior

Expected behavior

Minimal reproduction of the problem with instructions

I want to change class name from form-control to uk-input to work with getuikit css and i change flatpicker.vue component and re run watch command but its not updating
<input type="text" class="uk-input input" :id="id" :class="inputClass" :name="name" :placeholder="placeholder" :required="required" v-model="mutableValue" data-input>

[support] Flatpickr Plugins?

Sorry if this is a really noob question but im pretty new to the JS world and im not sure how i would enable one of the flatpickr built in plugins...

Here is my setup

import flatPickr from 'vue-flatpickr-component';
import 'flatpickr/dist/flatpickr.css';
import 'flatpickr/dist/themes/dark.css';

Vue.use(flatPickr);

and the config object

timeConfig: {
              enableTime: true,
              plugins: [new confirmDatePlugin({})],
              noCalendar: true,
              enableSeconds: false,
}

The errors i'm getting would indicate that im importing the plugin incorrectly, which wouldn't surprise me but i can't for the life of me figure out how to get it working, so I was hoping to get some help, thanks in advance.

on-change event not gets triggered after changing config dynamically

The component emits an on-change event that mimics the onChange hook from flatpickr.

If we change the config after the component has been mounted; None of the methods in config retains.

This is because of Object.assign does not handle this. Looking for a cheap and fast solution to get around this.

// changing config dynamically from your components
this.$set(this.configs.basic, 'mode', 'range');

P.S: Will try to use lodash/cloneDeep and see if this can fix Object.assign behavior .
P.S: Submit a PR flatpickr/flatpickr#1152

Emit Date instead of string

Great component to work with FlatPickr in Vue.js!

Just one question: the component emits the string value from the input field on change. If I have a date in my model, FlatPickr sets the initial date correctly but returns a string when a user selects a new date. Is there a way to get date object instead? Couldn't the component emit the date object from the FlatPickr instance instead of the input value?

[Vue warn]: Missing required prop: "value" found in FlatPickr

[x] Bug report => search github for a similar issue or PR before submitting
[ ] Feature request
[ ] Other, please describe

Tell about your platform

  • flatPickr version : 4.1.2
  • Vue.js version : 2.4.2
  • Browser name and version : Chrome|Firefox|Safari x.x.x
  • This package version : 5.0.0

Current behavior

[Vue warn]: Missing required prop: "value"

found in

Expected behavior
should not show this error when there is v-model

Minimal reproduction of the problem with instructions

Extend already pre selected date range by selecting only the last date

Tell about your platform

  • flatPickr version : 3.1.2
  • Vue.js version : 2.x.x
  • Browser name and version : Chrome 60+|Firefox
  • This package version : x.x.x

Current behavior

Date rage is pre-selected: Currently when i select the target date it take it as start date and wait to select the end date
Expected behavior

Date range is pre-selected: when click on the taget date it should extend the rage end point to that date like i have save range from 2017-10-01 to 2017-11-01
and it been highlighted on the picker. what i want is i select 2017-11-11 and it highlight dates like 2017-10-01 to 2017-11-11 by only selecting the last date not both start and end

Updating an instance `:config` will fire its `input` event

I'm submitting a ... (check one with "x")

[x] Bug report => search github for a similar issue or PR before submitting
[ ] Feature request
[ ] Other, please describe

Tell about your platform

  • Vue.js version : 2.4.2
  • Browser name and version : Chrome Version 60.0.3112.113 (Official Build) (64-bit) on Ubuntu
  • This package version : 4.0.0

Current behavior
I'm passing a :config object to my flat-pickr instance. Whenever I update that object (to update the minDate option for example), the @input event of the flat-pickr instance is fired.

Expected behavior
I would expect the @input to only fire when the actual value of the input change, not when it's config change.

Minimal reproduction of the problem with instructions
To give more context, I'm trying to build a form with two flat-pickr selectors. One for the "start date" and one for the "end date". I'd like to update the minDate option of the second instance to be the value of the first instance. In other words, I'd like to make sure it's not possible to pick an end date that is before the start date.

In the first instance @input, I'm changing the second instance config, but this also fires the second instance @input.

You can see the issue in action here: https://jsfiddle.net/2dLr1t1t/2/
Try to use the Foo date picker, and it will trigger the @input on the Bar datepicker as well. What is surprising is that it seems to only do it once (other updates of Foo won't update Bar).

v-model update not working from parent

I'm submitting a ... (check one with "x")

[x ] Bug report => search github for a similar issue or PR before submitting
[ ] Feature request
[ ] Other, please describe

Tell about your platform

Current behavior
if i set the date programaticly, it changes back to blank (empty string)
Expected behavior
the date should stay setted

Minimal reproduction of the problem with instructions
my Setup:

				flatpickr.l10ns.default.firstDayOfWeek = 1;
				flatpickr.localize(flatpickr.l10ns.de);
				Vue.use(httpVueLoader);
				Vue.use(MultiLanguage, window.LW_Sprachen);
				Vue.use(VueTippy);
				Vue.component('vuemultiselect', VueMultiselect.default);
				Vue.component('flat-pickr', VueFlatpickr);

the minimal component Looks like the following:

<template>
	<div>
		<flat-pickr v-model="lieferDatum" :config="{enableTime:false, dateFormat:'d.m.Y',weekNumbers: true, minDate:new Date()}" class="input"></flat-pickr>
		<button v-on:click="test">test</button>
		<button v-on:click="test2">test2</button>
		<div>{{lieferDatum}}</div>
	</div>
</template>

<script>
module.exports = {
	data:function() 
	{ 
		return { 
			lieferDatum:null
		};
	},
	methods:
	{
		test:function()
		{
			this.lieferDatum=new Date();
		},
		test2:function()
		{
			this.lieferDatum="30.01.2018";
		}
	}
}

</script>

i hope ist not a silly question because i'm a vue.js-newbie, but i don't know where to ask what i'm doing wrong

Picker remains focused after clicked outside

@ankurk91 As we are opening a picker to select a date and if we are not selecting a date and clicks outside, in this case datepicker remains as selected (focused).

And due to this, we need to click outside again to make it unselected.

Is there any solution for this ?

Don't send input event on programmaticly change date

I'm submitting a ...

[X] Bug report => search github for a similar issue or PR before submitting
[ ] Feature request
[ ] Other, please describe
  • flatPickr version : 4.2.4
  • Vue.js version : 2.5.13
  • Browser name and version : Chrome 63.0.3239.132
  • This package version : 6.2.0

Current behavior
When updating a date programatically, it sends an input event

Expected behavior
It shouldn't send an input event

Minimal reproduction of the problem with instructions
I don't think it should send back an input event. We already know that...

Here for the setDate, the second parameter should be false https://github.com/ankurk91/vue-flatpickr-component/blob/master/src/component.vue#L132

Imagine I've a dropdown to select pre-defined dates, and I've a custom entry for custom date. When I listen for input event,, I set the dropdown value to custom, and after the datepicker fire an event, which make the dropdown do it's thing and so on.

I believe that this date change should be done silently.

Date format issues

I'm submitting a ... (check one with "x")

[ x] Bug report => search github for a similar issue or PR before submitting
[ ] Feature request
[ ] Other, please describe

Tell about your platform

  • flatPickr version : 6.0.0
  • Vue.js version : 2.5.6
  • Browser name and version : Chrome

Current behavior

<flat-pickr
	v-model="filter.start"
	class="form-control date white-flatpickr"
	placeholder="Start date"
	dateFormat="n/j/Y"
	allowInput="true"
	name="start">
</flat-pickr>

With the dateFormat as shown when selecting a date like 1/7/2018 it first shows in the format 2018-01-07 and then when the picker is closed it switches to 01/07/2018.

Expected behavior
The n/j/Y format should render the date as 1/7/2018 and not have the date shown in a different format while open.

Placing a screenshot can make the project more attractive.

I'm submitting a ... (check one with "x")

[ ] Bug report => search github for a similar issue or PR before submitting
[x] Feature request
[ ] Other, please describe

Tell about your platform

  • flatPickr version : x.x.x
  • Vue.js version : 2.x.x
  • Browser name and version : Chrome|Firefox|Safari x.x.x
  • This package version : x.x.x

Current behavior

Expected behavior

Minimal reproduction of the problem with instructions

Time not being returned even when "enableTime" is set to true in config.

  • Vue flatPickr version : 2.4.1
  • Vue.js version : 2.1.10
  • Browser name and version : Chrome

Current behavior

On using v-model only a date is returned even when the "enableTime" has been set to true in the config though the selection of time input field gets enabled.

Expected behavior

Either an object or a string should be returned containing the details about the Date and Time selected.

Dynamically changing minDate/maxDate (date range picker)

[x] Other, please describe
Not sure if it's a bug or I am using it wrong (sorry for that).

Tell about your platform

  • flatPickr version : 3.0.0 (from unpkg)
  • Vue.js version : 2.4.2 (from unpkg)
  • Browser name and version : Chrome 55.0

Current behavior
Changing minDate and maxDate in the config objects does not trigger component redraw.

Expected behavior
Changing the dates in the fiddle below should update both pickers accordingly to allow proper date range selection (startDate < endDate).

Minimal reproduction of the problem with instructions
JSFiddle

  1. Change date in any picker from the example
  2. The other should update it's bounds accordingly (but it doesn't, so I can select an invalid date range with endDate before startDate like 2017-08-29 ~ 2017-08-10, for example)

P.S.: Thank you for creating this component. I was searching for a long time for a good-looking date picker, now the only thing left is getting it to work for me ๐Ÿ˜ƒ

Multiple instances of flat-pickr inside a single file component trigger unecessary onChange

I'm submitting a ... (check one with "x")

[x] Bug report => search github for a similar issue or PR before submitting
[ ] Feature request
[ ] Other, please describe

Tell about your platform

  • Vue.js version : 2.3.3
  • Browser name and version : Chrome 61.0.3163
  • This package version : 3.1.0

Current behavior

I have multiple instances of this flat-pickr component inside a single file component, each one mapped to a different v-model data property. Whenever I change any field in my custom component (even some others that are not faltpickr) all the flatpickr components emit the onChange event, eventhough their v-model values were not modified. I also tried mapping them to single data properties (startDate, endDate) that is, without using a nested structure such as filter.createdDate.start and the behaviour was the same.

Also, probably related to this issue, at some point I see several onChange events for each of the flat-pickr components. This suggests that the onChange is being registered multiple times and its handler stays in memory after the component is destroyed. If I have 4 flat-pickrs, I see 4 onChange events but at some point there will be 8 events and son on.

UPDATE: The second part of this issue where I mention multiple onChange being triggered is actually because I have other single file components that are not shown (v-show=false) whih in turn have flat-pickrs components inside, and they are all also triggering onChange. So this means that it seems like all flat-pickr instances are sharing the same onChange handler internally...that's the only explanation for both issues.

Expected behavior

The flatpickr components do not emit any event unless they are explicitly modified. Event handlers for onChange should not be duplicated.

Minimal reproduction of the problem with instructions

Here is a sample of how part of this form looks like, changing any field triggers an emit OnChange on all flat-pickrs.

          <div class="field">
            <h3 class="label">Date Created</h3>
            <div class="field dates">
              <div class="control">
                <flat-pickr v-model="filter.createdDate.start" :config="{static: true}" placeholder="Start date"></flat-pickr>
                <flat-pickr v-model="filter.createdDate.end" :config="{static: true}" placeholder="End date"></flat-pickr>
              </div>
            </div>
          </div>
          <div class="field">
            <h3 class="label">Wanted Date</h3>
            <div class="field dates">
              <div class="control">
                <flat-pickr v-model="filter.wantedDate.start" :config="{static: true}" placeholder="Start date"></flat-pickr>
                <flat-pickr v-model="filter.wantedDate.end" :config="{static: true}" placeholder="End date"></flat-pickr>
              </div>
            </div>
          </div>

can not set null date time value initially

flatpicker

template:
<Datepicker :config="until.config" :placeholder="$t('user.salesperson.until.placeholder')" class="form-control" id="until" name="until" ref="until" v-model="user._salesperson.until"> </Datepicker>

config:
config: { altFormat: 'j M Y', altInput: true, dateFormat: 'Y-m-d', locale: this.$store.getters.locale, wrap: true, }

[support] Editing vue component

Hello. Maybe you can explain to me. How can I change the architecture of a vue? For example wrap the input in a div? Those. I can somehow edit the structure of the vue element? Because I'm modifying the vue component, but nothing happens. I know that you can not change something in node_modules, but what if I want to add something of my own to your vue architecture?

required attribute not working

I set the required prop to true but the form validation does not stop the form from subit.
here is a sample code:
<Datepicker :config="date_to.config" :placeholder="$t('outbound.survey.form.date_to.placeholder')" :required="true" class="form-control" id="to" name="to" ref="to" v-if="!date_from.update" v-model="survey.dateTo" ></Datepicker>

flatpickr not working with vuematerial input

Environment

  • flatPickr version : 3.1.2
  • Vue.js version : 2.3.4
  • Browser name and version : Firefox 56.0, Chrome 63.0.3234

Current behavior
After selecting a date, the input field does not display the text

image

Expected behavior
flatPickr component should display the date, and can be bound to vue.js instance data

Minimal reproduction of the problem with instructions
Relevant code:

              <md-input-container>
                <md-icon>schedule</md-icon><label>Project Deadline</label> 
                <flat-pickr v-model="projectDeadline">
                </flat-pickr>
              </md-input-container>
<script>
import Vue from 'vue'
import flatPickr from 'vue-flatpickr-component'
import 'flatpickr/dist/flatpickr.css'

export default {
    components: {
        flatPickr
    },
    data () {
        return {
            projectDeadline: null,
        }
    },
}
</script>

Can't Disable Dates Reactively

I'm submitting a ... (check one with "x")

[ ] Bug report => search github for a similar issue or PR before submitting
[X ] Feature request
[ ] Other, please describe

Tell about your platform

  • flatPickr version : 4.0.0
  • Vue.js version : 2.4.2
  • Browser name and version : Chrome
  • This package version :4.0.0

Current behavior
Disabling Dates In Config is not working reactively

Expected behavior
I should be able to disable dates reactively.

Minimal reproduction of the problem with instructions
https://jsfiddle.net/63kzdwLx/18/

[support] How to use in Laravel-mix ?

How to use your package in Laravel?

If the code is an app.js

require('./bootstrap');

window.Vue = require('vue');
import Vue from 'vue';
import Buefy from 'buefy';

import UIkit from 'uikit';
import Icons from 'uikit/dist/js/uikit-icons';
UIkit.use(Icons);

Vue.use(Buefy);

var app = new Vue({
    el: '#app',
    data:{}
});

[support] update config on input change

I'm submitting a ... (check one with "x")

[ ] Bug report => search github for a similar issue or PR before submitting
[ ] Feature request
[ x ] Other, please describe, support

Tell about your platform

  • flatPickr version : 3.0.6
  • Vue.js version : 2.3.4
  • Browser name and version : Chrome 59.0.3071.115
  • This package version : 2.4.1
  • moment js version: 2.18.1

Current behavior
First of all I just started with vuejs 2 so I'm still at the beginning of the learning curve.
I'm firing two instances of flatpickr components in my view (check-in & check-out dates), both are working nice and v-model responds ok but I'm not able to figure out how to update the config of the second instance depending on the value of the first one.

Expected behavior
What I need is to set "minDate" of the second instance every time the first one changes.
Would be nice to be able to do something like this:

<flat-pickr :config="configs.checkin" v-model="checkinDate" on:change="updateMinDate"></flat-pickr>
<flat-pickr :config="configs.checkout" v-model="checkoutDate"></flat-pickr>

and on my js:

data: {
    checkinDate: '',
    checkoutDate: '',
    configs: {
        checkin: {
            dateFormat: 'd/m/Y',
            weekNumbers: false,
            minDate: moment().format('DD/MM/YYYY')
        },
        checkout: {
            dateFormat: 'd/m/Y',
            weekNumbers: false,
            minDate: moment().add(1, 'day').format('DD/MM/YYYY')
        }
     }
},
methods: {
    updateMinDate() {
        this.configs.checkout.minDate = this.checkinDate.add(1, 'day').format('MM/DD/YYYY');
    }
},

Any help will be appreciated.

enableTime popup wont close when click on background.

I'm submitting a ... (check one with "x")

[x] Bug report
 (I not sure my problem or bug, I try both **time** only and **date time** also got this problem, I think problem is when using **enableTime: true**)

Tell about your platform

  • flatPickr version : 4.0.6
  • Vue.js version : 2.1.10
  • Browser name and version : Chrome
  • This package version : 4.0.0

Current behavior
NONE

Expected behavior
click background will close the time picker like date picker.

Minimal reproduction of the problem with instructions
Below is my code:
Index.vue

<template>
<div>
<flat-pickr v-model="date" :config="dateConfig" ref="datePicker"></flat-pickr>
<flat-pickr v-model="time" :config="timeConfig" ref="timePicker"></flat-pickr>
</div>
</template>
<script>
    import flatPickr from 'vue-flatpickr-component';
    import 'flatpickr/dist/flatpickr.css';
    import 'flatpickr/dist/themes/material_blue.css'
    export default {
        components: {
            flatPickr
        },
        data(){
               date: "today",
                time: "00:00",
               dateConfig: {
                    minDate: "today",
                    dateFormat: "d-m-Y",
                    placeholder: 'Select Booking Date',
                    disable: [
                        function(date) {
                            // const curDate = new Date();
                            return (date.getDay() === 5 || date.getDay() === 6);

                        }
                    ]
                },
                timeConfig: {
                    enableTime: true,
                    noCalendar: true,
                    altFormat: "H:i",
                    dateFormat: "H:i",
                    placeholder: 'Select Booking Time',
                },
        },
        methods: {
           
        }
    }
</script

NOTE: It can close only when keyup esc key.

How to use open() on vuejs

I'm submitting a ... (check one with "x")

[x] How to trigger open() on vuejs

Tell about your platform

  • flatPickr version : 4.0.0
  • Vue.js version : 2.1.10
  • Browser name and version : Chrome
  • This package version : 4.0.0

Current behavior
NONE

Expected behavior
Trigger flatpickr with custom button

Minimal reproduction of the problem with instructions
Below is my code:
Index.vue

<template>
<div>
<button @click="chooseBooking" class="btn btn-pink">Book Now</button>
</div>
</template>
<script>
    import flatPickr from 'vue-flatpickr-component';
    import 'flatpickr/dist/flatpickr.css';
    import 'flatpickr/dist/themes/material_blue.css'
    export default {
        components: {
            flatPickr
        },
        data(){
            date: new Date()
        },
        methods: {
                chooseBooking(){
                         // Trigger flatpickr
                }
        }
    }
</script

Can't retrieving the flatpickr instance

Inside a .vue file:

In my script i import flatpickr:

import flatPickr from 'vue-flatpickr-component';

in my template I have:

<input type="text" id="myID" />

and then I try to get the instance like this in a mounted() hook:

    mounted () {
      const fp = flatPickr('#myID', {})
    }

Then in the console I get something like:

[Vue warn]: Error in mounted hook: "TypeError: __WEBPACK_IMPORTED_MODULE_1_vue_flatpickr_component___default(...) is not a function"

Obviously the component is not meant to work the same way as the chmln/flatpickr - but then how to I get the instance ?

With vue-router, only first route's flatPickr instances are loaded

I'm submitting a ... (check one with "x")

[x] Bug report => search github for a similar issue or PR before submitting
[ ] Feature request
[ ] Other, please describe

Tell about your platform

  • flatPickr version : 3.1.2
  • Vue.js version : 2.2.1

Current behavior

When using the component with vue-router using single-file components, instances of the flatpickr component only load for the first route visited. When I visit additional routes that include the component, those flatpickr instances are not being loaded.

Expected behavior

Ideally I'd be able to use instances of flatpickr throughout the app on any route visited. Is there a way to force the component to refresh or find new instances of flatpickr when new routes are visited?

[6.0.0] Insane number of events being emitted

This thing is emitting events like crazy. @on-day-create emits 100's of times on page load (multiply this by each instance of Flatpickr on the page), as well as @on-parse-config and @on-ready. This is horrible for performance and it kills the Vue debugger in Chrome.

Any chance of supporting plugins?

I'm submitting a ... (check one with "x")

[ ] Bug report => search github for a similar issue or PR before submitting
[x] Feature request
[ ] Other, please describe

Tell about your platform

  • flatPickr version : 3.0.0
  • Vue.js version : 2.4.2
  • Browser name and version : Chrome|Firefox|Safari [ALL]
  • This package version : x.x.x

Current behavior
Adding "plugins": [new confirmDatePlugin({})] to "config" results in error: ReferenceError: confirmDatePlugin is not defined

Expected behavior
Need support for plugins in general -- specifically "plugins": [new confirmDatePlugin({})]

Minimal reproduction of the problem with instructions
(see current behavior)

Issue with Vue's async event loop

[ ] Bug report => search github for a similar issue or PR before submitting
[ ] Feature request
[x] Other, please describe

Hi there,

Thank you for this component.
I ran into an issue caused by Vue's async event loop.

To reproduce, go to this fiddle: https://jsfiddle.net/6b94mxes/

  • Open calendar, the time should be updating every second
  • Scroll up once on the minutes location to increase the minute by one. Do this right before the seconds is about to change to the next second

Expected behavior: The minute place will increase and the calendar will stop updating until one minute has passed.

Current behavior: DOM input takes a few moments to change v-model. So this.date is not updated quickly enough and the minute place reverts back to what it was.

Any advice on how to work around this?

Thanks!

Limit the default events to be emitted

Right now component listen to all events available in flatpickr, i want to reduce the events list.

Here is events list and i have marked the events i want to keep -

  • onChange
  • onClose
  • onDestroy
  • onKeyDown
  • onMonthChange
  • onOpen
  • onYearChange
  • onValueUpdate
  • onReady
  • onPreCalendarPosition
  • onDayCreate
  • onParseConfig

You will be able to override this via :events="yourEventsList" prop.

Unexpected token export

Raises an error when adding export
<flat-pickr v-model="date" class="uk-input" type="text" placeholder="Where"></flat-pickr>

<script type="text/javascript">
export default {
    name: 'app',
    data() {
      return {
        form: {
          dateBasic: new Date(),
          dateTime: null,
          time: null,
          date: '2017-01-01',
          dateLocale: null,
          dateInline: null,
          dateModal: '',
          dateValidate: null,
          datePlugin: null
        },
        configs: {
          basic: {},
          wrap: {
            wrap: true,
            altFormat: 'M   j, Y',
            altInput: true,
            dateFormat: "Y-m-d",
          },
          timePicker: {
            wrap: true,
            enableTime: true,
            enableSeconds: true,
            noCalendar: true
          },
          dateTimePicker: {
            enableTime: true,
            dateFormat: 'd-m-Y H:i'
          },
          locale: {
            // https://chmln.github.io/flatpickr/localization/
            locale: Hindi,
            // https://chmln.github.io/flatpickr/events/
            onChange: this.onChange
          },
          inline: {
            inline: true
          },
          plugins: {
            enableTime: true,
            plugins: [new ConfirmDatePlugin({confirmText: 'Done'})]
          }
        },
      }
    },
    components: {
      flatPickr
    },
</script>

file app.js

require('./bootstrap');

window.Vue = require('vue');
import Vue from 'vue';
import Buefy from 'buefy';
import 'buefy/lib/buefy.css'
import UIkit from 'uikit';
import Icons from 'uikit/dist/js/uikit-icons';
import flatPickr from 'vue-flatpickr-component';
import 'flatpickr/dist/flatpickr.css';

UIkit.use(Icons);



Vue.use(flatPickr);
Vue.use(Buefy);

range plugin not supported

The range plugin not supported at the moment.
Range plugin requires two inputs, in our case these will be two different components and each component will have its own scope.

Support passive event listeners

I'm submitting a ... (check one with "x")

[ ] Bug report => search github for a similar issue or PR before submitting
[x] Feature request
[ ] Other, please describe

Tell about your platform

  • flatPickr version : N/A
  • Vue.js version : 2.5.2
  • Browser name and version : Chrome Version 61.0.3163.100 (Official Build) (64-bit)
  • This package version : 4.0.0

Current behavior
I create a form with one or more instances
When the page loads, I get the following message in my console:

flatpickr.js?1b10:579 [Violation] Added non-passive event listener to a scroll-blocking 'wheel' event. Consider marking event handler as 'passive' to make the page more responsive. See https://www.chromestatus.com/feature/5745543795965952

Expected behavior
VueJS now supports @click.passive (vuejs/vue#5132)
I do not want this message

How to validating fields via Vee-Validate?

I'm submitting a ... (check one with "x")

[x] Bug report => search github for a similar issue or PR before submitting
[ ] Feature request
[ ] Other, please describe

Tell about your platform

  • flatPickr version : 4.2.4
  • Vue.js version : 2.5.13
  • Vee-Validate: 2.0.3
  • Browser name and version : Safari 11.0.3
  • This package version : latest

Current behavior

I try to use Vue-Flatpickr-component with Vee-Validate as single Vue-component. My config for fields for Vee-Validate is simple: v-validate="'required'".

But Flatpickr make my inputs to type="hidden" and place his own input near. If I submit this input with empty value โ€” Vee-Validate doesn't show error, all is okay (actually not) and form submitted with empty field...

How can I solve this? Help please.

Expected behavior

Show error when has errors.

How to bind value with Date Object

Right now when I bind v-model with a variable, I can get the date value as a string. I want to get the date as a Date Object. Is it possible?

How to set the locale globally ?

Hi, first thanks for your work, it makes working with flatpickr a joy.

I was wondering how I could set the locale globally for all the instances of my component ?

Thanks a lot.

AM/PM switch does not always work when selecting a time

[ x ] Bug report

Tell about your platform

  • flatPickr version : 3.0.6
  • Vue.js version : 2.3.3
  • Browser name and version : Chrome|Firefox|Safari x.x.x
  • This package version : 2.4.1

Current behavior and reproduction

When using a date and time picker you are unable to swap from PM to AM until you use the hour fields spinner to get to the AM state. After the AM state has been reached once then you can click on AM/PM to change.

Edit: After a bit more testing it appears that it is simply that the the AM/PM is always stuck on PM when the hour is set to 12 PM.

Expected behavior

A user should be able to click on the AM/PM switch at any time and change it.

mismatched input and output

I'm submitting a ... (check one with "x")

[ ] Bug report => search github for a similar issue or PR before submitting
[ ] Feature request
[x ] Other, please describe

Tell about your platform

  • flatPickr version : 4.1.4

  • Vue.js version : 2.5.9

  • Browser name and version : Chrome Version 62.0.3202.94 (Official Build) (64-bit)

  • This package version : 5.0.0

Current behavior
Passing in a Date and a config format correctly displays the date, but returns just the string in the text box.

Expected behavior
I expected that if I passed in a Date, I would get a Date back,
ie: the component would use the date format string to format the input and parse the output, so that they matched.

Minimal reproduction of the problem with instructions
just use v-model to bind the component

Option enableTime change is not updating component

I would like to implement something like a allDay checkbox.
Set enableTime to false dynamically.

But when changing the options the component is not redrawing itself as mentioned.
The functionality is working fine! (Dialog closes when selecting a new date, but does not hide the Time select bar)

Quick jsFiddle

Available range after day passes

I'm submitting a ... (check one with "x")

[ ] Bug report => search github for a similar issue or PR before submitting
[ ] Feature request
[x ] Question

Current behavior
If a user is inactive from one day to the next, the current date is not available when they visit the next day.

For example, if they use the app on Dec 4, the most recent available date is Dec 4. But if they come back on Dec 5 and don't refresh, Dec 5 won't be available.

What's the best way to handle this situation? (Using range picker)

Thanks for the plugin and for your help!

Minimal reproduction of the problem with instructions
If you set your system date back one day, use flatpickr, then change the date forward, the current date should be unavailable

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.