Skip to content

Commit

Permalink
DatePicker: fix range-separator not working with more than one instan…
Browse files Browse the repository at this point in the history
…ces (ElemeFE#3378)
  • Loading branch information
Leopoldthecoder authored and baiyaaaaa committed Mar 9, 2017
1 parent afdd45e commit e695088
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions packages/date-picker/src/picker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ const NewPopper = {
beforeDestroy: Popper.beforeDestroy
};
let RANGE_SEPARATOR = ' - ';
const DEFAULT_FORMATS = {
date: 'yyyy-MM-dd',
month: 'yyyy-MM',
Expand Down Expand Up @@ -73,19 +72,19 @@ const DATE_FORMATTER = function(value, format) {
const DATE_PARSER = function(text, format) {
return parseDate(text, format);
};
const RANGE_FORMATTER = function(value, format) {
const RANGE_FORMATTER = function(value, format, separator) {
if (Array.isArray(value) && value.length === 2) {
const start = value[0];
const end = value[1];
if (start && end) {
return formatDate(start, format) + RANGE_SEPARATOR + formatDate(end, format);
return formatDate(start, format) + separator + formatDate(end, format);
}
}
return '';
};
const RANGE_PARSER = function(text, format) {
const array = text.split(RANGE_SEPARATOR);
const RANGE_PARSER = function(text, format, separator) {
const array = text.split(separator);
if (array.length === 2) {
const range1 = array[0];
const range2 = array[1];
Expand Down Expand Up @@ -306,7 +305,7 @@ export default {
).formatter;
const format = DEFAULT_FORMATS[this.type];
return formatter(value, this.format || format);
return formatter(value, this.format || format, this.rangeSeparator);
},
set(value) {
Expand All @@ -316,7 +315,7 @@ export default {
TYPE_VALUE_RESOLVER_MAP[type] ||
TYPE_VALUE_RESOLVER_MAP['default']
).parser;
const parsedValue = parser(value, this.format || DEFAULT_FORMATS[type]);
const parsedValue = parser(value, this.format || DEFAULT_FORMATS[type], this.rangeSeparator);
if (parsedValue && this.picker) {
this.picker.value = parsedValue;
Expand All @@ -330,7 +329,6 @@ export default {
},
created() {
RANGE_SEPARATOR = this.rangeSeparator;
// vue-popper
this.popperOptions = {
boundariesPadding: 0,
Expand Down Expand Up @@ -428,7 +426,7 @@ export default {
const format = DEFAULT_FORMATS.timerange;
ranges = Array.isArray(ranges) ? ranges : [ranges];
this.picker.selectableRange = ranges.map(range => parser(range, format));
this.picker.selectableRange = ranges.map(range => parser(range, format, this.rangeSeparator));
}
for (const option in options) {
Expand Down

0 comments on commit e695088

Please sign in to comment.