Skip to content

endless "change" triggers when setting option minDate/maxDate #957

Open
@giRobert

Description

@giRobert

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: #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());
    
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions