fix logic for multiple picker

This commit is contained in:
Sergio Crisostomo 2018-01-19 09:41:34 +01:00
parent 95eae081bc
commit d07b4f3301

View file

@ -265,8 +265,12 @@
}, },
computed: { computed: {
publicValue(){ publicValue(){
const isRange = this.type.includes('range'); if (this.multiple){
return isRange ? this.formatDate(this.internalValue) : this.formatDate(this.internalValue[0]); return this.internalValue.map(date => this.formatDate(date));
} else {
const isRange = this.type.includes('range');
return isRange ? this.formatDate(this.internalValue) : this.formatDate(this.internalValue[0]);
}
}, },
opened () { opened () {
@ -284,8 +288,10 @@
}, },
visualValue() { visualValue() {
const value = this.internalValue; const value = this.internalValue;
if (!value) return; if (!value) return;
if (this.multiple) return value.map(date => this.formatDate(date)).join(', ');
const formatter = ( const formatter = (
TYPE_VALUE_RESOLVER_MAP[this.type] || TYPE_VALUE_RESOLVER_MAP[this.type] ||
TYPE_VALUE_RESOLVER_MAP['default'] TYPE_VALUE_RESOLVER_MAP['default']
@ -294,7 +300,7 @@
return formatter(value, this.format || format); return formatter(value, this.format || format);
}, },
isConfirm(){ isConfirm(){
return this.confirm || this.type === 'datetime' || this.type === 'datetimerange'; return this.confirm || this.type === 'datetime' || this.type === 'datetimerange' || this.multiple;
} }
}, },
methods: { methods: {
@ -393,8 +399,10 @@
}, },
onPick(dates, visible = false) { onPick(dates, visible = false) {
if (this.type === 'multiple'){ if (this.multiple){
this.internalValue = [...this.internalValue, dates]; // TODO: filter multiple date duplicates const allDates = [...this.internalValue, dates].filter(Boolean);
const timeStamps = allDates.map(date => date.getTime()).filter((ts, i, arr) => arr.indexOf(ts) === i); // filter away duplicates
this.internalValue = timeStamps.map(ts => new Date(ts));
} else { } else {
this.internalValue = Array.isArray(dates) ? dates : [dates]; this.internalValue = Array.isArray(dates) ? dates : [dates];
} }