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

option and selected-option can be templated #202

Merged
merged 3 commits into from
Oct 1, 2017

Conversation

edwindj
Copy link
Contributor

@edwindj edwindj commented May 2, 2017

Thx for your great implementation!

I have made the following addition so options and selected-options can be templated, which is I think the underlying request of issue #193.

The following example from "dev.html" show a list of countries:

<v-select placeholder="custom option template" :options="options" multiple>

The changes I have made to vue-select make to following possible (showing the flags of the countries):

<v-select placeholder="custom option template" :options="options" multiple>
  <template slot="selected-option" scope="option">
    <img :src='"https://www.kidlink.org/icons/f0-" + option.value.toLowerCase() + ".gif"'/> 
      {{option.label}}
  </template>
  <template slot="option" scope="option">
    <img :src='"https://www.kidlink.org/icons/f0-" + option.value.toLowerCase() + ".gif"'/> 
      {{option.label}} ({{option.value}})
    </template>
</v-select>

(if you happen to have a better link to country flags, just change the urls...)

Best regards,

Edwin

@sagalbot sagalbot added this to the v2.3.0 milestone May 2, 2017
@sagalbot sagalbot self-assigned this May 2, 2017
@sagalbot
Copy link
Owner

sagalbot commented May 2, 2017

@edwindj thank you for the contribution! This has probably been the number one requested feature and has been on my roadmap for a long time now. When I saw scoped slots came out, I figured this would be possible but hadn't investigated yet. Going to checkout the branch and have a look now - but I don't expect to request any changes. Planning to have this rolled into the v2.3.0 release.

@sagalbot
Copy link
Owner

sagalbot commented May 2, 2017

I wonder if the API could be simplified just a touch by making the option slot the default, just so that you don't have to add the slot attribute. What are your thoughts?

@edwindj
Copy link
Contributor Author

edwindj commented May 2, 2017 via email

@marlonbuendia
Copy link

this isn't working for me.

                      <v-select
                        :on-change="selectBankProvider"
                        :options="bank_login.us_banks"
                        placeholder='Choose US Bank Provider'
                        label="bank_name"
                      >
                        <template slot="selected-option" scope="option">
                           testing
                        </template>
                      </v-select>

@edwindj
Copy link
Contributor Author

edwindj commented May 3, 2017

@marlonbuendia Did you check on the pull request? (note that the changes are not yet integrated in the master branch).

git fetch origin pull/202/head:optiontemplate
git checkout optiontemplate

@marlonbuendia
Copy link

marlonbuendia commented May 4, 2017

@edwindj I did this:

git clone https://github.com/sagalbot/vue-select.git
git fetch origin pull/202/head:optiontemplate
git checkout optiontemplate

result:

sh-3.2# cd vue-select/
sh-3.2# git fetch origin pull/202/head:optiontemplate
remote: Counting objects: 9, done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 9 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (9/9), done.
From https://github.com/sagalbot/vue-select

  • [new ref] refs/pull/202/head -> optiontemplate
    sh-3.2# git checkout optiontemplate
    Switched to branch 'optiontemplate'

what is next?

Should i replace node_modules/vue-select with this one?

I tried to rename the original: node_modules/vue-select_old
then copy the cloned one to node_modules.

Its still not working.

@marlonbuendia
Copy link

@sagalbot Hi did ever get to run it? How did you do implement it? im using webpack

@edwindj
Copy link
Contributor Author

edwindj commented May 5, 2017

It is running for me in the development environment:
npm run dev
http://localhost:8080 and the last example

@marlonbuendia
Copy link

@edwindj i still do not know how to make it run with templates. ill probably wait for the production update. for the mean time i am using vue-multiselect there template works perfectly with images.

@JustLey
Copy link

JustLey commented May 8, 2017

Great PR, I'm already using it! I was wondering, does it support multiple lines for the option template? Like:

Picture NAME/username
email

Edit: nevermind, my json response was lacking an information :) did it by separating the picture and all the multiline text from one another (with a div)

@marlonbuendia
Copy link

@JustLey how did you do it?

@ecmel
Copy link

ecmel commented May 9, 2017

Any news about status of this PR and version 2.3.0?

@marlonbuendia
Copy link

marlonbuendia commented May 9, 2017 via email

@edwindj
Copy link
Contributor Author

edwindj commented May 12, 2017

@marlonbuendia My PR does not include an updated vue-select.js (since that is undesired for PR's, only code-changes). To build the vue-select.js file, you will need to do the following from within the downloaded directory

npm install
npm run build

(the first command installs all build tools, the second builds all files needed for vue-select).
Hope this helps! Otherwise we have to wait until version 2.3.0.

@sagalbot
Copy link
Owner

@ecmel - sorry for the delay, just started a new job and haven't had much spare time to get this release pushed out. Things have settled a bit now, hoping to get this out in the next few days. Thanks for your patience!

@marlonbuendia
Copy link

@sagalbot great! ill probably use this instead of vue-multiselect

@marcelotk15
Copy link

pls merge will be awesome 💃 😄

@clarkeash
Copy link

This would be great 😄

@pymarco
Copy link

pymarco commented Jul 17, 2017

+1 please

@pymarco
Copy link

pymarco commented Aug 22, 2017

It appears this modification simply wraps the call to getOptionLabel with a slot.

Is anything further needed for this to merge?

@SergejKasper SergejKasper mentioned this pull request Sep 26, 2017
@sagalbot sagalbot merged commit 276bc86 into sagalbot:master Oct 1, 2017
@sagalbot
Copy link
Owner

sagalbot commented Oct 1, 2017

Option templating

@hemulin
Copy link

hemulin commented Nov 27, 2017

@edwindj Thanks for this great contribution.
Quick question:
I'm using the example you've provided in the beginning of this thread, and have a problem where the remove button (the small x) is falling out of line with the rest of the option

countries

The code that generates this (pug syntax):

h5 Countries
  v-select(@input="tagChange", :value.sync="this.countryTags", :options='allCountryTags', label='name', multiple)
    template(slot="selected-option" scope="option")
      div(v-if="option.icon !== null")
        img(:src="option.icon")
        |  {{ option.name }}
      template(slot="option" scope="option")
        div(v-if="option.icon !== null")
          img(:src="option.icon")
          |  {{ option.name }}

Any idea how can I control the button to be aligned with the rest of the option?

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

Successfully merging this pull request may close these issues.

None yet

9 participants