fragaria / angular-daterangepicker

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

locale configuration will be overridden when the page has multiple date picker directive #161

Closed zeng-ge closed 5 years ago

zeng-ge commented 8 years ago

the first locale: { format: 'MM-DD-YYYY h:mm' } the second locale: { format: 'MM-DD-YYYY' } result: the first format will be overridden.

why _mergeOpts function merge customOpts's locale configuration to the constant dateRangePickerConfig.locale?

_mergeOpts = function() { var extend, localeExtend; localeExtend = angular.extend.apply(angular, Array.prototype.slice.call(arguments).map(function(opt) { return opt != null ? opt.locale : void 0; }).filter(function(opt) { return !!opt; })); extend = angular.extend.apply(angular, arguments); extend.locale = localeExtend; return extend; }; el = $(element); customOpts = $scope.opts; opts = _mergeOpts({}, dateRangePickerConfig, customOpts);

nirmalgoswami commented 8 years ago

same issue here

tradiff commented 8 years ago

The following is a fix for this issue. Basically, put an empty object at the beginning of the array of objects to extend, so that you're not overwriting dateRangePickerConfig:

        _mergeOpts = function() {
          var extend, localeExtend;
          var locales = Array.prototype.slice.call(arguments).map(function(opt) {
            return opt != null ? opt.locale : void 0;
          }).filter(function(opt) {
            return !!opt;
          });
          locales.splice(0, 0, {});
          localeExtend = angular.extend.apply(angular, locales);
          extend = angular.extend.apply(angular, arguments);
          extend.locale = localeExtend;
          return extend;
        };

Sorry it's a comment and not a PR. It's late, and I'm not that familiar with coffee script.