Skip to content

Commit d6d8e3c

Browse files
authored
fix(b-form-input): modified value handling (#6084)
1 parent 42b30b4 commit d6d8e3c

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

src/mixins/form-text.js

+10-15
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,10 @@ export default {
7373
},
7474
props,
7575
data() {
76+
const { value } = this
7677
return {
77-
localValue: toString(this.value),
78-
vModelValue: this.value
78+
localValue: toString(value),
79+
vModelValue: this.modifyValue(value)
7980
}
8081
},
8182
computed: {
@@ -120,14 +121,15 @@ export default {
120121
}
121122
},
122123
watch: {
123-
value(newVal) {
124-
const stringifyValue = toString(newVal)
125-
if (stringifyValue !== this.localValue && newVal !== this.vModelValue) {
124+
value(newValue) {
125+
const stringifyValue = toString(newValue)
126+
const modifiedValue = this.modifyValue(newValue)
127+
if (stringifyValue !== this.localValue || modifiedValue !== this.vModelValue) {
126128
// Clear any pending debounce timeout, as we are overwriting the user input
127129
this.clearDebounce()
128130
// Update the local values
129131
this.localValue = stringifyValue
130-
this.vModelValue = newVal
132+
this.vModelValue = modifiedValue
131133
}
132134
}
133135
},
@@ -138,14 +140,6 @@ export default {
138140
mounted() {
139141
// Set up destroy handler
140142
this.$on('hook:beforeDestroy', this.clearDebounce)
141-
// Preset the internal state
142-
const value = this.value
143-
const stringifyValue = toString(value)
144-
/* istanbul ignore next */
145-
if (stringifyValue !== this.localValue && value !== this.vModelValue) {
146-
this.localValue = stringifyValue
147-
this.vModelValue = value
148-
}
149143
},
150144
methods: {
151145
clearDebounce() {
@@ -160,6 +154,7 @@ export default {
160154
return value
161155
},
162156
modifyValue(value) {
157+
value = toString(value)
163158
// Emulate `.trim` modifier behaviour
164159
if (this.trim) {
165160
value = value.trim()
@@ -171,7 +166,7 @@ export default {
171166
return value
172167
},
173168
updateValue(value, force = false) {
174-
const lazy = this.lazy
169+
const { lazy } = this
175170
if (lazy && !force) {
176171
return
177172
}

0 commit comments

Comments
 (0)