Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
giRobert opened this issue Sep 20, 2018 · 0 comments
Open

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

giRobert opened this issue Sep 20, 2018 · 0 comments

Comments

@giRobert
Copy link

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());
    
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant