fragaria / angular-daterangepicker

Angular.js wrapper for dangrossman/bootstrap-daterangepicker
MIT License
519 stars 372 forks source link

Parser always assumes it's range picker #247

Closed slavede closed 5 years ago

slavede commented 7 years ago

I have set date picker to be single date picker, but when value is set to empty string it returns object set to

{ startDate:null, endDate:null }

It should really do that only in the case when it is single date picker. The issue is here:

modelCtrl.$parsers.push(function(val) {
          var f, objValue, x;
          f = function(value) {
            return moment(value, opts.locale.format);
          };
          objValue = {
            startDate: null,
            endDate: null
          };
          if (angular.isString(val) && val.length > 0) {
            if (opts.singleDatePicker) {
              objValue = f(val);
            } else {
              x = val.split(opts.locale.separator).map(f);
              objValue.startDate = x[0];
              objValue.endDate = x[1];
            }
          }
          return objValue;
        });

objValue should be set depending on the options of the date range picker.