jonthornton / Datepair.js

A javascript plugin for intelligently selecting date and time ranges, inspired by Google Calendar.
https://www.jonthornton.com/Datepair.js
358 stars 87 forks source link

defaultTimeDelta not used if field already filled #99

Open footcow opened 6 years ago

footcow commented 6 years ago

Hello,

If you set a defaultTimeDelta to null for example then load a form with a time defined for both fields, start and end. If you set an anchor to start.

Then each time you modify the start field it'll add 3 hours to the end one.

defaultTimeDelta is not used in this case.

It works only if end date field is empty.

So I modified your code like this to have the defaultTimeDelta value used in all cases.

        _timeChanged: function(target){
            if (!this.startTimeInput || !this.endTimeInput) {
                return;
            }

            var startTime = this.settings.parseTime(this.startTimeInput);
            var endTime = this.settings.parseTime(this.endTimeInput);

            // Added those lines to have defaultTimeDelta really functionnal
            if (this.settings.defaultTimeDelta !== null) {
                this.timeDelta = this.settings.defaultTimeDelta;
            } else {
                this.timeDelta = null;
            }

            if (!startTime || !endTime) {
etc.

May be you will have a better solution, but it's works for me like this. Pretty sure it's the same for DefaultDateDelta ... but I do not use it right now ;)

Regards, Hervé