Tempus-dominus: [bug] onchange() event of <input> not triggered when a date is selected through datetimepicker

Created on 19 Feb 2014  路  8Comments  路  Source: Eonasdan/tempus-dominus

When attaching datetimepicker directly to the <input> element, selecting a date will trigger the onchange() event of the <input> as it should, however the datetimepicker doesn't work correctly (see https://github.com/Eonasdan/bootstrap-datetimepicker/issues/155 )

However when attaching datetimepicker to the <div> surrounding the <input> with a separate <span> for the date selection - as is the default configuration , selecting a date in the picker will NOT trigger the onchange event of the <input> - thus breaking any subsequent validation or onchange="submit()" features.

Most helpful comment

$(document).on('dp.change', 'input.datepicker', function() {
   alert('changed');
});

should work

All 8 comments

check the staging branch to see if your issue has been fixed

do you still have this issue with the latest version?

Seems not fixed to me:

<!-- Filter -->
<div class="filters">
    <div class="form-group">
        <label>Created at</label>
        <div class="col-sm-8">
            <input class="datepicker" name="created_at" type="text">
        </div>
    </div>
</div>

<script type="text/javascript">
    $(function() {
        // Datepickers
        $('input.datepicker').datetimepicker({
            format: 'DD/MM/YYYY',
        });
    });

    // Filters
    $(document).on('change', 'div.filters input', function (e) {
        alert('changed');
    });
</script>

Alert is never prompted.

$(document).on('dp.change', 'input.datepicker', function() {
   alert('changed');
});

should work

@jawu yes, it works.

Thanks.

the dp.change event also includes the current date and the previous date, by the way

not working dude

In version 4.17.37, 'change' event is not triggered on the input when a date is selected. It's true that on version 3.x 'change' was triggered when date was selected.

If you have listeners for 'change', just add 'dp.change' also:

$(inputSelector).on('change dp.change', function(e){
    // do stuff...
})
Was this page helpful?
0 / 5 - 0 ratings

Related issues

hmaidasani picture hmaidasani  路  5Comments

dleffler picture dleffler  路  4Comments

benbhale picture benbhale  路  5Comments

callum-resdiary picture callum-resdiary  路  4Comments

jnm2 picture jnm2  路  5Comments