Editor datetime trigger change
Editor datetime trigger change
Hi Alan.
I saw the changelog of 1.6 that now selecting a date from the datepicker with the mouse triggers the onchange event for dependent. The problem I found is that I had other events listening on the input field but they never got triggered.
I have tried to add another listener to the editor-datetime-button
but because you are using stopPropagation
my listener never got called either, so I ended up adding the following simple fix:
I altered the following function as follows:
_writeOutput: function ( focus ) {
var date = this.s.d;
// Use moment if possible - otherwise it must be ISO8601 (or the
// constructor would have thrown an error)
var out = window.moment ?
window.moment.utc( date, undefined, this.c.momentLocale, this.c.momentStrict ).format( this.c.format ) :
date.getUTCFullYear() +'-'+
this._pad(date.getUTCMonth() + 1) +'-'+
this._pad(date.getUTCDate());
this.dom.input.val( out );
this.dom.input.trigger('change'); // Trigger a change event on the input!
if ( focus ) {
this.dom.input.focus();
}
}
Hope it helps.
Replies
Thanks for posting this. I'll take a look into including this into Editor in future.
Allan
Hi Alan, just found the same issue, could you please add the following line? It does the trick for me. Thanks!
this.dom.input.trigger('change');
@jukimv1986 - Editor should be triggering the
change
event on thedatetime
input already, as you can see in this example: http://live.datatables.net/bopugaba/1/edit .Regards,
Allan
@allan sorry but I meant when using the calendar as standalone (as in this thread https://datatables.net/forums/discussion/comment/85747/#Comment_85747) that line was the one missing for me to trigger the change event.
Ah I see - thanks for the clarification. I've noted this in our bug tracker to get it addressed for Editor 1.9.3, which I expect around the end of the month.
Regards,
Allan