evansmwendwa / ng2-daterangepicker

Usage Demos update in this url >>>
https://codesandbox.io/s/6yr1zm18w3
MIT License
132 stars 88 forks source link

Start and End date value for input not auto updating. #104

Closed akshayinnopix closed 4 years ago

akshayinnopix commented 6 years ago

If you try to update the start date and end date from an external event it doesn't get updated. The reason is your render and attachment are called before the value is changed. That is the reason the component and the options are updated but input shows the same value.

Existing code:

DaterangePickerComponent.prototype.ngDoCheck = function () {
    var optionsChanged = this._differ['options'].diff(this.options);
    var settingsChanged = this._differ['settings'].diff(this.config.settings);

    if (optionsChanged || settingsChanged) {
        this.render();
        this.attachEvents();
        if (this.activeRange && this.datePicker) {
            console.log("active");
            console.log(this.activeRange);
            this.datePicker.setStartDate(this.activeRange.start);
            this.datePicker.setEndDate(this.activeRange.end);
        }

    }
};

A workaround for this is calling render and attachEvents after the start and end date is set, like this:

DaterangePickerComponent.prototype.ngDoCheck = function () {
    var optionsChanged = this._differ['options'].diff(this.options);
    var settingsChanged = this._differ['settings'].diff(this.config.settings);

    if (optionsChanged || settingsChanged) {
        if (this.activeRange && this.datePicker) {
            console.log("active");
            console.log(this.activeRange);
            this.datePicker.setStartDate(this.activeRange.start);
            this.datePicker.setEndDate(this.activeRange.end);
        }
        this.render(); // this is what makes it work
        this.attachEvents();
    }
};

If the existing code is intentional, I'd like to know what the correct workaround is. If my suggested workaround is acceptable, let me know, so I can make a pull request.

JanuszCh commented 5 years ago

I have the same issue. I try to update start and end date by [options] but UI does not get updated. @akshayinnopix Thank You for that work around! Works for me.

evansmwendwa commented 4 years ago

Closed due to inactivity