vue-bootstrap-typeahead icon indicating copy to clipboard operation
vue-bootstrap-typeahead copied to clipboard

How to clear the typehead (still not working model change)

Open vlapenkov opened this issue 5 years ago • 3 comments

  <vue-bootstrap-typeahead    
        ref="usersAutocomplete"     
        v-model="username"
        :data="users"
        :serializer="item => item.login"
        @hit="$event=>addUser($event)"
      />

and this.username='' still not working, but this.$refs.usersAutocomplete.inputValue = '' is working. But this is not best solution

vlapenkov avatar May 31 '19 13:05 vlapenkov

Ran into the same issue myself. PR #21 addresses this.

jhalag avatar Jun 18 '19 22:06 jhalag

I merged a fix for this into my fork (https://github.com/mattzollinhofer/vue-typeahead-bootstrap) of this project that I'm actively maintaining. Give it a try.

You can find it on npm here: https://www.npmjs.com/package/vue-typeahead-bootstrap.

I hope this helps!

mattzollinhofer avatar Feb 26 '20 02:02 mattzollinhofer

A quick and dirty solution. Assign a ref to the typeahead this way:

<vue-bootstrap-typeahead ref="inputAutocompletado" :serializer="serializadorAutocompletadoClientes" @input="refrescarClientesDeAutocompletadoConBusquedaActual" @hit="onClienteSeleccionado" v-model="busqueda" :data="clientesDelAutocompletado" placeholder="Busca un cliente por nombre o documento" />

Please note that the ref is inputAutocompletado . Then when you want to clear it, make this:

this.$refs.inputAutocompletado.inputValue = "";

And this way you can clear it. The explanation is: inputAutocompletado refers to the typeahead itself. It has its own data as a component, and the prop that is binded to the real input is in the inputValue prop. If we change that prop, it is changed in the input and in the Typeahead

parzibyte avatar Feb 28 '22 18:02 parzibyte