Commit d9ff845f63632050909fe394184b2bdaf976c545

Authored by Sergio Crisostomo
1 parent 2fb29fae

Emit input event in mounted if parsed value diffs

Showing 1 changed file with 8 additions and 5 deletions   Show diff stats
src/components/date-picker/picker.vue
@@ -135,9 +135,6 @@ @@ -135,9 +135,6 @@
135 }, 135 },
136 default: 'bottom-start' 136 default: 'bottom-start'
137 }, 137 },
138 - options: {  
139 - type: Object  
140 - },  
141 transfer: { 138 transfer: {
142 type: Boolean, 139 type: Boolean,
143 default: false 140 default: false
@@ -250,7 +247,7 @@ @@ -250,7 +247,7 @@
250 typeof this.options.disabledDate === 'function' && 247 typeof this.options.disabledDate === 'function' &&
251 this.options.disabledDate; 248 this.options.disabledDate;
252 const valueToTest = isArrayValue ? newDate : newDate[0]; 249 const valueToTest = isArrayValue ? newDate : newDate[0];
253 - const isDisabled = disabledDateFn && disabledDateFn(valueToTest) 250 + const isDisabled = disabledDateFn && disabledDateFn(valueToTest);
254 251
255 if (newValue !== oldValue && !isDisabled) { 252 if (newValue !== oldValue && !isDisabled) {
256 this.emitChange(); 253 this.emitChange();
@@ -375,10 +372,16 @@ @@ -375,10 +372,16 @@
375 publicValue(now, before){ 372 publicValue(now, before){
376 const newValue = JSON.stringify(now); 373 const newValue = JSON.stringify(now);
377 const oldValue = JSON.stringify(before); 374 const oldValue = JSON.stringify(before);
378 - if (newValue !== oldValue) this.$emit('input', now); // to update v-model 375 + const shouldEmitInput = newValue !== oldValue || typeof now !== typeof before;
  376 + if (shouldEmitInput) this.$emit('input', now); // to update v-model
379 }, 377 },
380 }, 378 },
381 mounted () { 379 mounted () {
  380 + const initialValue = this.value;
  381 + const parsedValue = this.publicValue;
  382 + if (typeof initialValue !== typeof parsedValue || JSON.stringify(initialValue) !== JSON.stringify(parsedValue)){
  383 + this.$emit('input', this.publicValue); // to update v-model
  384 + }
382 if (this.open !== null) this.visible = this.open; 385 if (this.open !== null) this.visible = this.open;
383 } 386 }
384 }; 387 };