luisfarzati / ng-bs-daterangepicker

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

model does not update when selecting current... #59

Open deifos opened 9 years ago

deifos commented 9 years ago

... model does not seem to update if you select current date on both calendars, this only happens when you load the page after you select a different date and apply and then try to select current date on both calendars it seems to work just fine.

asborisov commented 9 years ago

If I understood write, then I have the same problem. Spets to reproduce:

  1. Insert in html
<input type="daterange" format="DD MMMM YYYY" locale="advSearchCtrl.locale" ng-model="createdRange">
  1. In controller
createdRange = {};
  1. Now open daterangepicker there are selected default value = today
  2. Click OK
  3. Model is not updating

The reson in this code of directive:

$element.daterangepicker(options, function(start, end, label) {
    var modelValue = ngModel.$viewValue;

    if (angular.equals(start, modelValue.startDate) && angular.equals(end, modelValue.endDate)) {
        return;
    }

    $scope.$apply(function() {
        ngModel.$setViewValue({
            startDate: (moment.isMoment(modelValue.startDate)) ? start : start.toDate(),
            endDate: (moment.isMoment(modelValue.endDate)) ? end : end.toDate()
        });
        ngModel.$render();
    });
});

Now let's see bootstrap-daterangepicker code:

...
// On init step
this.startDate = moment().startOf('day');
this.endDate = moment().endOf('day');
...
// And callback condition
if (!this.startDate.isSame(this.oldStartDate) || !this.endDate.isSame(this.oldEndDate))
    this.notify();
...
asborisov commented 9 years ago

Can somebode explane to dangrossman than we need such kind of changes?