jQuery-Timepicker-Addon icon indicating copy to clipboard operation
jQuery-Timepicker-Addon copied to clipboard

endless "change" triggers when setting option minDate/maxDate

Open giRobert opened this issue 6 years ago • 0 comments

Hello there!

Lets imagine I have 2 inputs fields using the datetimepicker.

One field is the start and the other the end field. Both fields can be changed without the "onSelect" event by changing the input date directly.

This will then cause the on change. on change we are doing a reset of minDate and maxDate.

And now the problem happends. setting minDate and maxDate is again triggering the on change event and so it causes a endless recursion.

how can i avoid that?

it seems this ticket is exactly the same problem: https://github.com/trentrichardson/jQuery-Timepicker-Addon/issues/672

can this be fixed? is there any workaround? can i forbid to call "change"-event somehow?

this is my code:

HTML:

<input class="dtp_fake_start" value="" type="text">
<input class="dtp_fake_end" value="" type="text">

JS

$(".dtp_fake_start").datetimepicker({
    timeFormat: ezdatetime_time_format_string,
    hour: 19,
    minute: 30,
    onSelect: function(selected) {
        var end_date_field = $(this).closest(".editform").find(".dtp_fake_end");
        end_date_field.datetimepicker("option","minDate", selected);
        ...........
    },
    onClose: function(dateText, inst) {
       ......
    }
}).on("change", function () {
    $(this).closest(".editform").find(".dtp_fake_end").datetimepicker("option","minDate", $(this).val());
    
});
$(".dtp_fake_end").datetimepicker({
    timeFormat: ezdatetime_time_format_string,
    hour: 19,
    minute: 30,
    onSelect: function(selected) {
        if( $(this).closest(".editform").find(".dtp_fake_start").datetimepicker('getDate') != null )
        {
            $(this).closest(".editform").find(".dtp_fake_start").datetimepicker("option","maxDate", selected);
        }
    }
}).on("change", function () {
	$(this).closest(".editform").find(".dtp_fake_start").datetimepicker("option","maxDate", $(this).val());
    
});

giRobert avatar Sep 20 '18 00:09 giRobert