flatpickr / flatpickr

lightweight, powerful javascript datetimepicker with no dependencies
https://flatpickr.js.org
MIT License
16.18k stars 1.46k forks source link

Uncaught TypeError: Cannot read property 'add' of undefined #574

Closed deangibson89 closed 7 years ago

deangibson89 commented 7 years ago

When trying to initialise Flatpickr I get the following error:

flatpickr.js:1176 Uncaught TypeError: Cannot read property 'add' of undefined at setupInputs (flatpickr.js:1176) at init (flatpickr.js:21) at Flatpickr (flatpickr.js:1399)

Expected Behavior

Flatpickr should initialise and I should be able to click inside the input field to active Flatpickr.

Current Behavior

Getting the error mentioned above.

Steps to Reproduce (for bugs)

Create an input: <input class="flatpickr" type="text" placeholder="Select Date.."> Call Flatpickr in input's class: flatpickr(".flatpickr");

Your Environment

chmln commented 7 years ago

Hello,

Looks like you're using new Flatpickr(..) and providing a string instead of the element's node.

Create an input: Call Flatpickr in input's class: flatpickr(".flatpickr");

I'm unable to reproduce. Please provide a fiddle :+1:

edouard-lopez commented 7 years ago

@chmln could you provide a working example of what you mean as the docs is confusing and the following doesn't work:

const Flatpickr = require("flatpickr");
new Flatpickr(document.querySelector('#start-date'), {});

related #350

edouard-lopez commented 7 years ago

In angular-1.5 with webpack-2.2 I git it to work by moving the instanciation into the component initialization:

HTML

<input type="text" id="start-date" ng-model="vm.startDate" ng-change="vm.updateEndDate()"></input>

Component

require('flatpickr');
angular.module('app').component('rangeDatepicker', {
        template: require('./range-datepicker.html'),
        controller: controller,
        controllerAs: 'vm',
    });

function controller(businessDays, moment) {
    var vm = this;
    activate();
    function activate() {
        document.getElementById('start-date').flatpickr({ inline: true });
    }