Merge pull request #3070 from SergioCrisostomo/datepicker
Pass Strings to @on-change and Dates to v-model
This commit is contained in:
commit
ab3ff750a3
2 changed files with 17 additions and 11 deletions
|
@ -178,7 +178,7 @@
|
|||
};
|
||||
},
|
||||
computed: {
|
||||
publicValue(){
|
||||
publicVModelValue(){
|
||||
if (this.multiple){
|
||||
return this.internalValue.slice();
|
||||
} else {
|
||||
|
@ -189,6 +189,11 @@
|
|||
return (isRange || this.multiple) ? val : val[0];
|
||||
}
|
||||
},
|
||||
publicStringValue(){
|
||||
const {formatDate, publicVModelValue, type} = this;
|
||||
if (type.match(/^time/)) return publicVModelValue;
|
||||
return Array.isArray(publicVModelValue) ? publicVModelValue.map(formatDate) : formatDate(publicVModelValue);
|
||||
},
|
||||
opened () {
|
||||
return this.open === null ? this.visible : this.open;
|
||||
},
|
||||
|
@ -296,8 +301,8 @@
|
|||
},
|
||||
emitChange () {
|
||||
this.$nextTick(() => {
|
||||
this.$emit('on-change', this.publicValue);
|
||||
this.dispatch('FormItem', 'on-form-change', this.publicValue);
|
||||
this.$emit('on-change', this.publicStringValue);
|
||||
this.dispatch('FormItem', 'on-form-change', this.publicStringValue);
|
||||
});
|
||||
},
|
||||
parseDate(val) {
|
||||
|
@ -388,7 +393,7 @@
|
|||
type(type){
|
||||
this.onSelectionModeChange(type);
|
||||
},
|
||||
publicValue(now, before){
|
||||
publicVModelValue(now, before){
|
||||
const newValue = JSON.stringify(now);
|
||||
const oldValue = JSON.stringify(before);
|
||||
const shouldEmitInput = newValue !== oldValue || typeof now !== typeof before;
|
||||
|
@ -397,9 +402,9 @@
|
|||
},
|
||||
mounted () {
|
||||
const initialValue = this.value;
|
||||
const parsedValue = this.publicValue;
|
||||
const parsedValue = this.publicVModelValue;
|
||||
if (typeof initialValue !== typeof parsedValue || JSON.stringify(initialValue) !== JSON.stringify(parsedValue)){
|
||||
this.$emit('input', this.publicValue); // to update v-model
|
||||
this.$emit('input', this.publicVModelValue); // to update v-model
|
||||
}
|
||||
if (this.open !== null) this.visible = this.open;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue