Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clicking on a date in the datepicker does not trigger the JS change event #60

Open
harvzor opened this issue May 31, 2016 · 5 comments
Open

Comments

@harvzor
Copy link

harvzor commented May 31, 2016

If an input element has it's onchange event watched by some JS, this onchange event will not get triggered when a date in the datepicker is selected.

$('input').on('change', function() {
     // If a date is picked from the datepicker and not manually put in, then this event will not fire.
    console.log('Input value changed.');
});

This is likely linked with this issue:
http://stackoverflow.com/questions/3179385/val-doesnt-trigger-change-in-jquery

@harvzor
Copy link
Author

harvzor commented May 31, 2016

The above is a feature request. For a temporary fix for users affected by this issue, use the following onSelect event.

$('.air-datepicker').datepicker({
    onSelect: function(formattedDate, date, inst) {
        $(inst.el).trigger('change');
    }
});

@SergeySagan
Copy link

It would be great if this was built into the datepicker

@kirill-voronov
Copy link

+1

@yosypandriyash
Copy link

Try this:
In this case, my datapicker is allowed inside .modal_datapicker div, so you can try addEventListener("click") or jquery on("click") and when click call to a function that returns the date from the datepicker. Its not very good solution but it works:

$(".modal_datepicker").on("click", function(e){
e.preventDefault();
var date = getDataPIckerDate(); //Call to function returns the value of datapicker
if(!date){ //In case, this funciton can returns false if any date is selected
date = "Please select date";
}
$("input.showDateFromDtaepicker").val(date);
})

@ulrichkrenn
Copy link

Hi,

in IE 11
...onSelect: function(formattedDate, date, inst) { $(inst.el).trigger('change');}...
is not called when the date field is cleared (only if the date is changed.). It works with Chrome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants