What JQuery event will fire when the value in the Yii2 DateTimePicker changes?

Web Tips Q & ACategory: Krajee Yii2 ExtensionsWhat JQuery event will fire when the value in the Yii2 DateTimePicker changes?
jpg0002 asked 1 week ago

I have two DateTimePickers. I want to fire a JQuery function when the value in the Picker changes. What JQuery event fires when you finish selecting a date, hour, and minutes and the value appears in the textbox?
I have tried keyup keypress blur change mouseup mousedown. All but change work as expected.
Here’s my code:

Start your code here
echo DateTimePicker::widget([
'id' => 'transitionaction-datetime_asset_delivered',
'name' => 'TransitionAction[datetime_asset_delivered]',
'size' => 'sm',
'options' => [],
'convertFormat' => true,
'pluginEvents' => [
"show.daterangepicker" => "function(e) {
//set startDate
$('#transitionaction-datetime_asset_delivered-datetime').datetimepicker('setStartDate', $('#transitionaction-datetime_asset_removed-datetime').datetimepicker('getDate'));
}",
"hide.daterangepicker" => "function(ev, picker) {
customValidate();
}",
],
'pluginOptions' => [
'format' => $viewOptions['datePickerFormat'],
'startDate' => $viewOptions['datePickerStart'],
'todayHighlight' => true,
'autoclose' => true,
],
]);
$this->registerJs('
$("#transitionaction-datetime_asset_delivered").on("keyup keypress blur change mouseup mousedown", function() {
customValidate();
});
', View::POS_END);

jpg0002 replied 1 week ago

The JQuery code in question is the last function that calls customValidate(). I would like to know how to trigger this function when the user uses the date and time pop-ups to enter a value. Due to the blur, it will call customValidate() when the user tabs off of the widget or clicks on another. As you can see, manually entering a date-time string will also call the function, as will clicking on the text box.

Thanks in advance for any help or guidance you can give!

Login or register to contribute or comment.

Login   Register