fix logic for multiple picker
This commit is contained in:
parent
95eae081bc
commit
d07b4f3301
1 changed files with 14 additions and 6 deletions
|
@ -265,8 +265,12 @@
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
publicValue(){
|
publicValue(){
|
||||||
|
if (this.multiple){
|
||||||
|
return this.internalValue.map(date => this.formatDate(date));
|
||||||
|
} else {
|
||||||
const isRange = this.type.includes('range');
|
const isRange = this.type.includes('range');
|
||||||
return isRange ? this.formatDate(this.internalValue) : this.formatDate(this.internalValue[0]);
|
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];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue