Uncaught TypeError: undefined is not a function

150 views Asked by At

I am doing a leaflet plugin and i have a problem with the calendar.

    var calen = L.DomUtil.create('div', className, container);
    calen.href = '#';
    L.DomEvent
        .addListener(calen, 'click', L.DomEvent.stopPropagation)
        .addListener(calen, 'click', L.DomEvent.preventDefault)
        .addListener(calen, 'click', this._buttonExtendCalendaClicked, this);

    calen.datepicker({
        changeMonth: true,
        changeYear: true,
        altField: '#date-input',
        altFormat: 'mm/dd/yy',
        defaultDate: new Date().getTime()
    });

the error is: Uncaught TypeError: undefined is not a function

I don't know how can I do it

1

There are 1 answers

1
blgt On

calen is initialised by leaflet's DomUtil.create() which returns an HTMLElement

jqueryui defines its widgets as jquery plugins, so you need to wrap the HTMLElement in a jquery collection:

$(calen).datepicker({ /* ... options ... */ });