nazar-pc / PickMeUp

Really simple, powerful, customizable and lightweight standalone datepicker
BSD Zero Clause License
615 stars 191 forks source link

Current Jquery version #173

Closed mirahost closed 7 years ago

mirahost commented 7 years ago

What is the current version for jquery? I am updating an older site which is using the jquery dependent version. I've included the latest version into the site without jquery dependency, but we are still using jquery and it isnt working correctly.

My specific issue is with the change callback. This was previously called through the initialization, but this method doesnt work anymore:

 $('#pickup_date').pickmeup({
    format : 'm/d/Y',
    hide_on_select: true,
    calendars : 2,
    change : function (formatted_date) {
       $('#return_date').val(addDays(formatted_date,2));
    }
  }); 

The docs recommend this method, but it doesnt work with jquery:

pickmeup(element);
element.addEventListener('pickmeup-change', function (e) {
    console.log(e.detail.formatted_date); // New date according to current format
    console.log(e.detail.date);           // New date as Date object
})

What is the correct jquery method for the change callback?

nazar-pc commented 7 years ago

Why can't you just call addEventListener and need jQuery here?

nazar-pc commented 7 years ago

If you desperately want jQuery the same can be done with jQuery, but what is the point of doing so?:

$(element).on('pickmeup-change', function (e) {
    console.log(e.detail.formatted_date); // New date according to current format
    console.log(e.detail.date);           // New date as Date object
})
mirahost commented 7 years ago

Why can't you just call addEventListener and need jQuery here?

I am not sure how to do that.

nazar-pc commented 7 years ago

I am not sure how to do that.

You've quoted the exact piece that does it last time:) Anyway, you can use jQuery version I've posted earlier.

mirahost commented 7 years ago

I understand what you are saying. What I originally quoted wasn't working. Which spurred me to ask for help. This gets a response, but returns "TypeError: e.detail is undefined"

$("#pickup_date").on('pickmeup-change', function (e) { console.log(e.detail.formatted_date); // New date according to current format console.log(e.detail.date); // New date as Date object });

nazar-pc commented 7 years ago

This is better, so event is fired and captured by jQuery, just e.detail property isn't there while it should. Add debugger statement at the beginning of the callback and open Dev Tools in your browser. Then you can inspect e variable and see what it inside.

mirahost commented 7 years ago

Just so you can get a full view of what I am trying to do:

This previously worked:

    var d = new Date();
    pickmeup('#pickup_date',{
        format : 'm/d/Y',
        hide_on_select: true,
        calendars : 2,
        min : d,
        change : function (formatted_date) {
            $('#return_date').val(addDays(formatted_date,2));
        }
    });

Now that the above no longer works, I am exploring new options. This doesnt work yet:

    $("#pickup_date").on('pickmeup-change', function (e) {
        $('#return_date').val(addDays(e.formatted_date,2));
    });
nazar-pc commented 7 years ago

Here is another demo that works: https://jsfiddle.net/qx152r6r/176/ Maybe you have very old jQuery or something else.

mirahost commented 7 years ago

Add debugger statement at the beginning of the callback and open Dev Tools in your browser. Than you can inspect e variable and see what it inside.

Thank you. You got me on the right track so I can sort this out.