Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vuetify - How to trigger method when clear a v-text-field

is there a way to call a method while clearing a text-field with Vuetify?

<v-text-field
    class="mt-2 mb-0"
    clearable
    solo
    v-model="searchQuery"
    append-icon="search"
    @click:append-outer="searchCos"
   label="Nom de compagnies ou mots-clés">
 </v-text-field>

...
onClear() {
doSomethingHere
}

Thanks

Francis

like image 634
Francis Beaulieu Avatar asked Sep 30 '18 01:09

Francis Beaulieu


People also ask

How do I turn off Vuetify form?

Update 1: Since version 2.3. 0 v-form has disabled property, it sets to true it disables all children inputs. They haven't implemented such a thing to disable all children of a `v-form` yet. You should bind `disabled` prop to `false` for every control.

What is V text Vue?

The v-text directive is a Vue. js directive used to update a element's textContent with our data. It is just a nice alternative to Mustache syntax. First, we will create a div element with id as app and let's apply the v-text directive to this element with data as a message.

What is V Main in Vuetify?

The v-app component is the root of your application and a direct replacement for the default Vue entrypoint, <div id="app"> . The v-main component is a semantic replacement for the main HTML element and the root of your application's content.


2 Answers

You can use the @click:clear="()" so you can clear your text at the same time it will call the function.

Here's the example

https://codepen.io/anon/pen/ePmLOg?editors=1010

like image 53
ßiansor Å. Ålmerol Avatar answered Oct 13 '22 00:10

ßiansor Å. Ålmerol


Use the clear-icon-cb prop. This allows you to use a custom callback function when the clear icon when clicked.

<v-text-field
  clearable
  :clear-icon-cb="onClearClicked">
</v-text-field>

onClearClicked () {
  // do something
}
like image 34
Brian Lee Avatar answered Oct 12 '22 23:10

Brian Lee