Skip to content

<b-form-input> becoming out of sync with value if using formatter #2657

Closed
@kalvenschraut

Description

@kalvenschraut

When a form-input has a formatter on it stripping out characters in the case of trying to only allowing numerial values in a text input, the input value can sometimes not match up with the emitted value.

codepen: https://codepen.io/Kalvens/pen/Lqabrj (type any nonnumerical character in the input)
browser: Chrome Version 69.0.3497.100 (Official Build) (64-bit)
OS: linux

I believe the issue comes from

updateValue(value) {
value = this.stringifyValue(value)
if (this.localValue !== value) {
// keep the input set to the value before modifiers
this.localValue = value
if (this.number) {
// Emulate .number modifier behaviour
const num = parseFloat(value)
value = isNaN(num) ? value : num
} else if (this.trim) {
// Emulate .trim modifier behaviour
value = value.trim()
}
// Update the v-model
this.$emit('update', value)
}
},

the value is already formatted at that point so if the formatter strips out all of the characters leaving the value to be an empty string, nothing will happen even though the input still has a value set for it

I was playing around with your source code and doing

if (this.localValue !== value) {
    ...
} else if (this.$el.value !== value)  {
  this.$el.value = value;
}

seems to fix my issue, but I am not sure if that would be affecting anything else using the mixin.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions