vue2-autocomplete icon indicating copy to clipboard operation
vue2-autocomplete copied to clipboard

How set Value on page load

Open salvatorelapi opened this issue 7 years ago • 4 comments

initValue work if value is static

data(){ return { locality_name: 'aas' } }

when locality_name is changed by other function value is alwais "aas".

In documentation we have this.$refs.autocomplete.setValue(string) but not work. How can fix ?

salvatorelapi avatar Feb 10 '18 13:02 salvatorelapi

@salvatorelapi you need to specify autocomplete as the ref for the child component, after which this.$refs.autocomplete.setValue(string) will work:

<autocomplete
      ref="autocomplete"
      :url="userSearchUrl"
      anchor="email"
      label="first_name"
      :on-select="addUser">
</autocomplete>

You can then set the value through:

export default {
  props: ['userSearchUrl'],
  components: {
    autocomplete: Vue2Autocomplete
  },
  created: function() {
    this.$refs.autocomplete.setValue('new value')
  }
}

constantm avatar Feb 22 '18 10:02 constantm

initValue not working import file data update autocomplete first item ?. image view image

NguyenTheSon avatar Jun 11 '18 02:06 NguyenTheSon

@NguyenTheSon i've got the same issue

teddy-dubal avatar Jun 13 '18 00:06 teddy-dubal

@teddy-dubal you can use this.$refs.autocomplete.setValue solve the problem

NguyenTheSon avatar Jun 18 '18 02:06 NguyenTheSon