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

Usign Initial prop to show active option #3

Open
jujogi opened this issue Sep 24, 2018 · 5 comments
Open

Usign Initial prop to show active option #3

jujogi opened this issue Sep 24, 2018 · 5 comments

Comments

@jujogi
Copy link

jujogi commented Sep 24, 2018

Hi, thanks for amazing and useful select.

I trying to use 'initial' prop, but the option doesn't select, only shows like an option. If I click outside, the dropdown will be deactivated.

captura de pantalla 2018-09-24 a la s 10 34 08 a m

Thanks for help,
Regards

@robrogers3
Copy link
Owner

robrogers3 commented Sep 24, 2018 via email

@robrogers3
Copy link
Owner

robrogers3 commented Sep 24, 2018 via email

@anoviel
Copy link

anoviel commented Dec 5, 2018

I like to use this component in more applications.
as mentioned preselecting / databinding is a problem yet, so i tested a bit:
using

<template>
    <vue-single-select
        id="post-selector"
        v-model="post"
        :options="posts"
        placeholder="Select tribe"
        :value="post"
        :get-option-description="label"
        :get-option-value="value"
        >
    </vue-single-select>
</template>

<script>
export default {
    data() {
        return {
            post: null,
            posts: [
                {id: 1, name: "test"},
                {id: 2, name: "test2"},
                {id: 3, name: "test3"},
            ],
        }
    },
    methods: {
        label(option){
            return option.name
        },
        value(option){
            return option.id
        }
    }
}
</script>

i used props for specific label / value functions to match my needs
i had to edit your code slightly to enable preselect depending on :value prop

//VueSingleSelect.vue
data() {
    return {
      searchText: null,
      selectedOption: this.value,   //<--- edited here
      dropdownOpen: false
    };
  },

Could that be a valid solution for you?

Greetings,
Jan Radtke

@robrogers3
Copy link
Owner

can you make a pull request for this.

@gribben
Copy link

gribben commented Oct 16, 2020

@robrogers3 This would be a very useful feature. I have tested the proposed fix above and it seems to do the trick. Can you add this?

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

4 participants