Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Options not changing when updated programmatically #23

Open
theashcodes opened this issue Sep 7, 2021 · 2 comments
Open

Options not changing when updated programmatically #23

theashcodes opened this issue Sep 7, 2021 · 2 comments

Comments

@theashcodes
Copy link

theashcodes commented Sep 7, 2021

I have three <vue-select/> components on a page.
I am using the :from prop to supply a function that will load options based on the selected value from the first dropdown.
But the options shown in the second dropdown is not updating while changing the options in first dropdown.

It works perfectly fine for the first time. Once the options are loaded, it is not changing on the subsequent changes.

@theashcodes
Copy link
Author

Making the from non-static fixes this issue. But is there any option to invoke the function (to update options) while changing the first dropdown?

@desislavsd
Copy link
Owner

desislavsd commented Sep 27, 2021

@theashcodes this certainly is something I have to make a default behavior. Till then though you can easily achieve it through one of the following steps, knowing that the component internally uses the .search method to update its options:

  1. Make it default behavior for your app during plugin setup:
Vue.use(VueSelect, {
    name: 'vSelect',
    mixin: {
        watch: {
            from() {
                this.search(true) // force refresh options ( ignore cache )
            }
        }
    }
})
  1. If you do not setup the plugin globally but you only use the component on demand you can still do the same:
import { vSelect } from '@desislavsd/vue-select'

vSelect = {
    mixins: [vSelect],
    watch: {
        from() {
            this.search(true)
        },
    },
}

export default {
    components: { vSelect },
}
  1. You can also use $refs like so:
<template>
    <v-select ... @change="$refs.secondSelect.search(true)" />
    <v-select ... ref="secondSelect" />
</template>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants