mugifly / jquery-simple-datetimepicker

Date & time picker for jQuery, It's simple & clean.
http://mugifly.github.com/jquery-simple-datetimepicker
Other
260 stars 182 forks source link

Added new onSelect Callback function executed when a new Date value i… #150

Closed jasondavis closed 8 years ago

jasondavis commented 9 years ago

Added new onSelect Callback function executed when a new Date value is selected/clicked on.

    "onSelect": function(handler, targetDate){
        window.alert(handler.getDate());
        console.log(targetDate);
    },
jasondavis commented 9 years ago

This is a simple addition...

Line 1082:

    $picker.data('onSelect', opt.onSelect);

Around line 878 I added:

                // Generate the handler of a picker
                var $input = $(this);
                var handler = new PickerHandler($picker, $input);

                // Call a event-hanlder for onSelect
                var func = $picker.data('onSelect');
                if (func != null) {
                    console.log("dtpicker- Call the onSelect handler");
                    func(handler, targetDate);
                }

Line 1236

        "onSelect": null,

And now I can use this new callback like this to make AJAX saves and update DOM when Date is selected:

$('#btn_generate').click(function(){

    window.alert("Generate");

    $('#date_jit').appendDtpicker({

        "onSelect": function(handler, targetDate){
            window.alert(handler.getDate());
            console.log(targetDate);
        },

    });
});
mugifly commented 9 years ago

Hi, Jason! Thanks very much for nice code :) I was wondering if you could write an example code into jquery.simple-dtpicker.html ?

jasondavis commented 9 years ago

of course, thanks i'll do it today!

jasondavis commented 9 years ago

I added a simple example based on the other callback examples. One thing to note is that in the example I have set "dateOnly": true, as I don't use the Time feature in my current project and the callback is fired when the date is selected so it might need a little work to trigger onSelect when a Date and Time is selected, however when only a date is shown it should function as it does now.

When I get some time I can try to modify it to work with Date and Time selections, for now this is just for Date selections so the example has the Time disabled.

royzrj commented 8 years ago

@mugifly do you need help merging this pull? I think it's a needed modification, specially regarding inline calendars.

mugifly commented 8 years ago

I'm sorry for too late merge.

@royzrj Thanks for your thoughtfulness. It needed merge the conflict with few fixes about dateOnly mode and inline mode.

royzrj commented 8 years ago

Great!

dmatora commented 8 years ago

I wonder why is it invisible on http://mugifly.github.io/jquery-simple-datetimepicker/jquery.simple-dtpicker.html

royzrj commented 8 years ago

@dmatora what is invisible?

dmatora commented 8 years ago

onSelect example

royzrj commented 8 years ago

@dmatora if you want to always show the calendar you must use "inline: true" option

dmatora commented 8 years ago

I'm saying that onSelect example exists on github.com but missing on github.io

dmatora commented 8 years ago

i checked github.io, didn't see, implemented it, started creating pull request, and then realized that it's actually already implemented, i'm sure i'm not only person who got confused

royzrj commented 8 years ago

Yeah, the online examples page is not up to date. You should check the examples page from the repository, you'll find it there.