vue-select icon indicating copy to clipboard operation
vue-select copied to clipboard

Event for clearable

Open itlpps opened this issue 3 years ago • 23 comments

I want get an event when click on "x" for clear, please

itlpps avatar May 12 '21 18:05 itlpps

+1

darrinmn9 avatar May 12 '21 20:05 darrinmn9

+1

vitornovo54 avatar May 13 '21 12:05 vitornovo54

+1

LucasVanni avatar May 13 '21 12:05 LucasVanni

I solved this with patch-package.

Replace node_module/vue-select/dist/vue-select.js for this content vue-select.js and apply a new patch.

Usage:

<v-select
    ...
    @option:clear="onClear"
/>

itlpps avatar May 13 '21 14:05 itlpps

Or you can resolve this in a more elegant way. Vue-selects offer a way to define the component. So you can simple use vue render function to mount any event. I currently creating a render function then adding an $emit. Since it's a component, all you need to do is to listen it in the parent. It's more work but it will maintain the package without actually patching it.

in your view

<v-select 
  :components="{Deselect}"
/>

in your vue or component. I'm currently using in a component.

...
data() {
  return {
    Deselect: {
      render: (createElement) => {
          return createElement('span', {
            on: {
              click: ()=>{
                this.$emit('deselect',this);
              }
            }
          },'❌');
      }
   }
 }
...

Then you can mount a listener for example in the created state.

created(){
    this.$on('deselect',this.someMethod);
},

https://vue-select.org/guide/components.html#deselect

vitornovo54 avatar May 13 '21 14:05 vitornovo54

I realize there are possible work arounds, so thanks to those who commented. but it just strikes me as odd that a component exposes an "X" button that you can click, wouldn't expose a custom event to listen for that button click.

darrinmn9 avatar May 13 '21 15:05 darrinmn9

yeah, me too 😩. That's why I'm doing this way. It will be updated once available without yet including another package. As you just saw, you're not alone in this topic 😆

vitornovo54 avatar May 13 '21 15:05 vitornovo54

I also need this :)

danimalweb avatar Sep 24 '21 23:09 danimalweb

any solutions

daniel007enirman avatar Oct 12 '21 07:10 daniel007enirman

I solved this with patch-package.

Replace node_module/vue-select/dist/vue-select.js for this content vue-select.js and apply a new patch.

Usage:

<v-select
    ...
    @option:clear="onClear"
/>

better create PR for this

daniel007enirman avatar Oct 15 '21 10:10 daniel007enirman

@sagalbot Please pay attention

akulmambetov avatar Oct 26 '21 05:10 akulmambetov

I solved this with patch-package.

Replace node_module/vue-select/dist/vue-select.js for this content vue-select.js and apply a new patch.

Usage:

<v-select
    ...
    @option:clear="onClear"
/>

Is this fix added to the current package yet?

SaqibSyed1014 avatar Mar 19 '22 12:03 SaqibSyed1014

+1

ecuci avatar Apr 29 '22 12:04 ecuci

+1

camille500 avatar May 18 '22 15:05 camille500

One year later, using the same component in another project and still don't have this event :( I made a fork and implemented this for myself, using vue 3 (v4.0.0-beta.3)

yarn add git+https://github.com/itlpps/vue-select.git#event-cleared

usage:

<v-select
    ....
    @option:cleared="onClear"
></v-select>

itlpps avatar Jul 01 '22 00:07 itlpps

One year later, using the same component in another project and still don't have this event :( I made a fork and implemented this for myself, using vue 3 (v4.0.0-beta.3)

yarn add git+https://github.com/itlpps/vue-select.git#event-cleared

usage:

<v-select
    ....
    @option:cleared="onClear"
></v-select>

thanks @itlpps it works, but console gave me a warning like this : "option:cleared" but it is neither declared in the emits option nor as an "onOption:cleared" prop.

How to fix this by the way?

mamlzy avatar Jul 07 '22 10:07 mamlzy

+1

igorespin avatar Jul 19 '22 17:07 igorespin

Since we don't have an explicit event yet, pasting the snippet of the workaround I used.

watch: {
    search(value) {
        if (value === null) {
            // Your logic here
        }
    },
}

<v-select v-model="search">

sharan-mohandas-tfs avatar Oct 11 '22 05:10 sharan-mohandas-tfs

@clear="handleQuery"

gotoworld avatar Mar 03 '23 10:03 gotoworld

Any update here?

Iterator98 avatar Jul 09 '23 22:07 Iterator98

Any update here?

Ali7med avatar Mar 14 '24 06:03 Ali7med