Topic: Cannot change input value programmatically

shilu911 pro asked 5 years ago


Hi there, When mdb-input components are created, I cannot change values by setting value attribute, so I added watch: { value(val) { this.innerValue = val; this.$forceUpdate(); } } in the input.vue, then I am able to change the value programmatically after components are created, but I have another issue: after the input events are triggered, I am not able to change the value programmatically again. Through the Vue debugger, I can see the value and innerValue fields are changed, but the input box on the UI still has the value before changing. PS: when I change <component... /> to <input... /> in the input.vue, it starts to work. Any idea why? Thank you, Lu Shi

Jakub Strebeyko staff answered 5 years ago


Hi,

This will be probably how the issue will get handle in the official release, too. Thanks for reaching out!

Kuba


smiker free answered 5 years ago


I solved it using mixin, hope it will be useful
Mixin `input.vue`:

<script>
import { Input } from 'mdbvue'
export default {
extends: Input,
watch: {
value: function (val) {
this.innerValue = val
}
}
}
</script>

Now it can be using in components as:

<template lang="pug">
f-input(type='text', value='', label="Name", v-model="user_name")
</template>
<script>
import Inpt from '@/components/input'
export default {
components: {
'f-input': Inpt
},
data() { return {
user_name: "test_name"
}}
}
</script>

Jakub Strebeyko staff answered 5 years ago


Lu shi 你好, Unfortunately, a quick look into it did not answer the question of why change in innerValue does not get reflected in the actual input value. It has been added to the MDB Vue development list as a bug and shall be dealt with soon. In case you have any kind of insight or you figure it out before we do, please share solution here. Thanks for reaching out! With Best Regards, Kuba

shilu911 pro commented 5 years ago

Hi Jakub, My solution is changing the component name in the input.vue from "component" to "input", then it started to work. btw, your notification system sent me 7 emails when you posted your answer here. Best Regards, Lu Shi

Jakub Strebeyko staff commented 5 years ago

Hi, There seems to be little justification for not making input an component, right - we will have a look into that and have it fixed shortly. When it comes to the notification - there is a task force already delegated to investigate. Thanks for all this valuable input! Best Regards, Kuba

smiker free commented 5 years ago

Hi Jakub,
How is the fix going?


Jakub Strebeyko staff commented 5 years ago

It is scheduled for the release by the end of the month, but it is to be treated as an ETA, not a promise. In the meantime, for people operating on our code base, have you perhaps tried Lu Shi's solution? I worked the last time I checked.

Best,
Kuba



Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue

  • ForumUser: Pro
  • Premium support: No
  • Technology: MDB Vue
  • MDB Version: 4.6.0
  • Device: iMac
  • Browser: Chrome
  • OS: MacOS
  • Provided sample code: No
  • Provided link: No