b-form-input v-on:input is triggered before actual nput value and v-model is changed
See original GitHub issueDescribe the bug
With <input>
onInput event is triggered after input and v-model values are changed
With <b-form-input>
onInput event (v-on:input) is triggered before those values are changed
I have recorded a video for this: https://user-images.githubusercontent.com/34946346/187000396-e867e291-49f6-4c5c-9fb1-479a3527eb65.mp4
First part of video with <b-form-input>
, last part with regular <input>
To Reproduce Steps to reproduce the behavior:
- Create vue3 project with vue-cli and add bootstrap-vue-3 like this (main.js):
import { createApp } from 'vue'
import App from './App.vue'
import "bootstrap/dist/css/bootstrap.min.css"
import BootstrapVue3 from 'bootstrap-vue-3'
import 'bootstrap/dist/css/bootstrap.css'
import 'bootstrap-vue-3/dist/bootstrap-vue-3.css'
const app = createApp(App)
app.use(BootstrapVue3)
app.mount('#app')
- Add this vue component somewhere (doesn’t matter where):
<template>
<form class="mt-4 mb-4">
<input v-model="levelid" type="number" name="levelid" max="99999999" min="1" placeholder="12345678" id="levelid" required @input="formValueChanged" />
<b-button :variant="formValid ? 'success' : 'outline-danger'" id="submit" squared="false">Предложить</b-button>
</form>
</template>
<script>
export default {
name: "requestPage",
data(){
return {
formValid: false,
levelid: ''
}
},
methods: {
formValueChanged()
{
alert(this.levelid)
this.formValid = +this.levelid > 100 && +this.levelid < 100000000
}
}
}
</script>
- run app
- try to enter character in input
Expected behavior After I enter character it appears in the input and then alert with new input value is shown
Actual behavior After I enter character alert with old input value shows up, then character appears in input
Environment (please complete the following information):
- OS: Artix linux (openrc)
- Version 0.2.11 (from npm)
Issue Analytics
- State:
- Created a year ago
- Comments:5
Top Results From Across the Web
How should I use v-model and v-on:change for an input select ...
It seems to be a problem with the component. It would happen because change event is firing before the event which is responsible...
Read more >vmodel changes do not trigger "change" event in text-input ...
I would expect changes to the value to trigger a change on the input, which should update the "not-empty-state" class accordingly. Right now, ......
Read more >Form Input Bindings - Vue.js
v -model will ignore the initial value , checked or selected attributes found on any form elements. It will always treat the current...
Read more >Inputs — Essentials ⚡️ FormKit — Vue Forms, Supercharged
FormKit ships with turbocharged inputs for developing production-ready forms ... value prop, v-model , or node.input() ) to set the value of the...
Read more >Using v-model for Two-Way Binding in Vue.js | DigitalOcean
To bind the value of an input element to a property of your component's data, use v-model="dataProperty" like so.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’ll attempt to develop a fix on Monday. People shouldn’t normally need to use nextTick themselves.
It would be in line with how vue behaves, the actual values are updated before the DOM in a single tick.
Edit: The reason was because the
@input
was emitted before@update:modelValue
Yes
Thanks, I somehow didn’t know
nextTick
existed and this method fixes the issue but it’sthis.$nextTick