Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call a function on append-icon click in Vuetify.js?

I need the append-icon="close" to call @click="clearSearch()"

Right now I'm implementing it with a dedicated button:

 <v-text-field 
       v-model="search" 
       class="search" 
       label="search" 
       prepend-icon="search" 
       append-icon="close">
 </v-text-field>    

 <v-btn @click="clearSearch()"></v-btn>

  • I've tried adding append-icon-cb="clearSearch()" but it doesn't work and I don't know why
  • I've also tried simply using clearable, it clears the input but all the elements stay "filtered". I don't know how clearable works but my clearSearch() method simply does: clearSearch() {this.search = ""} and it works, that's why I use the custom clear input method
like image 996
Un1 Avatar asked Dec 28 '17 22:12

Un1


People also ask

How do I use append icons in Vuetify?

Icon eventsclick:prepend , click:append , click:append-outer , and click:clear will be emitted when you click on the respective icon. Note that these events will not be fired if the slot is used instead.

How do you delete a text field in Vuetify?

You can use the @click:clear="()" so you can clear your text at the same time it will call the function. Show activity on this post. Use the clear-icon-cb prop. This allows you to use a custom callback function when the clear icon when clicked.

What is Vuetify in VUE JS?

Vuetify is a Vue UI Library with beautifully handcrafted Material Components. No design skills required — everything you need to create amazing applications is at your fingertips. Get Started.


Video Answer


2 Answers

Use @click:append="clearSearch", :append-icon-cb is deprecated. (Source)

like image 124
wkornilow Avatar answered Sep 17 '22 15:09

wkornilow


Solved it, here's the solution:

To avoid that problem you should bind the attribute with : symbol:

:append-icon-cb="clearSearch"

And don't put () otherwise it will not work (as @Traxo mentioned)

like image 23
Un1 Avatar answered Sep 20 '22 15:09

Un1