Skip to content

fix(b-form-input/b-form-textarea): v-model handling (closes #6078) #6084

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 24, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions src/mixins/form-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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
}
}
},
Expand All @@ -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() {
Expand All @@ -160,6 +154,7 @@ export default {
return value
},
modifyValue(value) {
value = toString(value)
// Emulate `.trim` modifier behaviour
if (this.trim) {
value = value.trim()
Expand All @@ -171,7 +166,7 @@ export default {
return value
},
updateValue(value, force = false) {
const lazy = this.lazy
const { lazy } = this
if (lazy && !force) {
return
}
Expand Down