luisfarzati / ng-bs-daterangepicker

AngularJS directive for bootstrap-daterangepicker
http://luisfarzati.github.io/ng-bs-daterangepicker/
MIT License
246 stars 167 forks source link

Date reset to "today" on first click on "cacel" button #66

Open arcadeJHS opened 9 years ago

arcadeJHS commented 9 years ago

Hi! As stated by issue #40, daterange reset to today date when I open it the first time and click on "cacel" button.

I solved it modifying the code in the change watcher this way:

            $scope.$watch($attributes.ngModel, function (modelValue) {
                if (!modelValue || (!modelValue.startDate)) {
                    ngModel.$setViewValue({ startDate: moment().startOf('day'), endDate: moment().startOf('day') });
                    return;
                }
                $element.data('daterangepicker').setStartDate(modelValue.startDate);
                $element.data('daterangepicker').setEndDate(modelValue.endDate);

                $element.data('daterangepicker').updateView();
                $element.data('daterangepicker').updateCalendars();
                $element.data('daterangepicker').updateInputText();
            });

setStartDate and setEndDate in fact also replace the "old" stored value. Is it the right way? Maybe the change could be integrated in a new source version?

giorgiosironi commented 8 years ago

:+1: