From 5a2c95400c1e90b66d2c8f0b42750be3612a8083 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20M=C3=BCller?= Date: Tue, 24 Nov 2020 14:36:55 +0100 Subject: [PATCH] fix(b-form-input): modified value handling --- src/mixins/form-text.js | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/mixins/form-text.js b/src/mixins/form-text.js index 49f6050fa9c..e3c64f1004f 100644 --- a/src/mixins/form-text.js +++ b/src/mixins/form-text.js @@ -73,9 +73,10 @@ export default { }, props, data() { + const { value } = this return { - localValue: toString(this.value), - vModelValue: this.value + localValue: toString(value), + vModelValue: this.modifyValue(value) } }, computed: { @@ -120,14 +121,15 @@ export default { } }, watch: { - value(newVal) { - const stringifyValue = toString(newVal) - if (stringifyValue !== this.localValue && newVal !== this.vModelValue) { + value(newValue) { + const stringifyValue = toString(newValue) + const modifiedValue = this.modifyValue(newValue) + if (stringifyValue !== this.localValue || modifiedValue !== this.vModelValue) { // Clear any pending debounce timeout, as we are overwriting the user input this.clearDebounce() // Update the local values this.localValue = stringifyValue - this.vModelValue = newVal + this.vModelValue = modifiedValue } } }, @@ -138,14 +140,6 @@ export default { mounted() { // Set up destroy handler this.$on('hook:beforeDestroy', this.clearDebounce) - // Preset the internal state - const value = this.value - const stringifyValue = toString(value) - /* istanbul ignore next */ - if (stringifyValue !== this.localValue && value !== this.vModelValue) { - this.localValue = stringifyValue - this.vModelValue = value - } }, methods: { clearDebounce() { @@ -160,6 +154,7 @@ export default { return value }, modifyValue(value) { + value = toString(value) // Emulate `.trim` modifier behaviour if (this.trim) { value = value.trim() @@ -171,7 +166,7 @@ export default { return value }, updateValue(value, force = false) { - const lazy = this.lazy + const { lazy } = this if (lazy && !force) { return }