Merge pull request #3029 from SergioCrisostomo/fix-datepicker-output

Pass correct arguments to `on-change` callback
This commit is contained in:
Aresn 2018-02-26 09:54:40 +08:00 committed by GitHub
commit 7600961f69
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 94 additions and 5 deletions

View file

@ -183,7 +183,9 @@
return this.internalValue.slice();
} else {
const isRange = this.type.includes('range');
const val = this.internalValue.map(date => date instanceof Date ? new Date(date) : (date || ''));
let val = this.internalValue.map(date => date instanceof Date ? new Date(date) : (date || ''));
if (this.type.match(/^time/)) val = val.map(this.formatDate);
return (isRange || this.multiple) ? val : val[0];
}
},
@ -293,8 +295,8 @@
);
},
emitChange () {
this.$emit('on-change', this.visualValue, this.publicValue);
this.$nextTick(() => {
this.$emit('on-change', this.publicValue);
this.dispatch('FormItem', 'on-form-change', this.publicValue);
});
},

View file

@ -163,6 +163,8 @@ const RANGE_FORMATTER = function(value, format) {
if (start && end) {
return formatDate(start, format) + RANGE_SEPARATOR + formatDate(end, format);
}
} else if (!Array.isArray(value) && value instanceof Date){
return formatDate(value, format);
}
return '';
};