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

Append new option in single mode #150

Closed
Glideh opened this issue Oct 5, 2021 · 5 comments
Closed

Append new option in single mode #150

Glideh opened this issue Oct 5, 2021 · 5 comments

Comments

@Glideh
Copy link

Glideh commented Oct 5, 2021

I was expecting to be able add new options in single mode but it doesn't seem to do it

<Multiselect
  v-model="value"
  :searchable="true"
  :createTag="true"
  :options="options"
/>
const appConf = {
  data: () => ({
    value: null,
    options: [
      { value: 'batman', label: 'Batman' },
      { value: 'robin', label: 'Robin' },
      { value: 'joker', label: 'Joker' },
    ],
  })
}

Here if I type "Moonnight" then [Enter] I can see value is now { value: 'Moonnight', label: 'Moonnight } but not getting added on options.

Am I missing something ?

@Glideh
Copy link
Author

Glideh commented Oct 6, 2021

Here is my workaround for now:

<Multiselect
  v-model="value"
  :searchable="true"
  :createTag="true"
  :options="options"
  @select="select"
/>
const appConf = {
  data: () => ({
    value: null,
    options: [
      { value: 'batman', label: 'Batman' },
      { value: 'robin', label: 'Robin' },
      { value: 'joker', label: 'Joker' },
    ],
  }),
  methods: {
    select(optionLabel) {
      if (this.options.find(option => option.label === optionLabel)) return;
      this.options.push({ id: optionLabel, label: optionLabel });
    }
  }
}

createTag effectively allows to select a new option but @tag doesn't get called.
Maybe the following props/events should be renamed if we allow creating options too.

  • appendNewTag -> appendNewOption
  • createTag -> createOption
  • @tag -> @option

@jamols09
Copy link

jamols09 commented Oct 6, 2021

Gotta ask is this related to this? #152

@Glideh
Copy link
Author

Glideh commented Oct 6, 2021

Seems not related, I'm talking about the single mode here

@jamols09
Copy link

jamols09 commented Oct 6, 2021

Seems not related, I'm talking about the single mode here

Quite funny mine was also trying to implement single mode, forgot to mention/implement it also but it fixed my problem. If multiselect is inside the v-if condition (conditionally rendered) the newly created tag would remain. It wouldn't disappear.

@adamberecz
Copy link
Collaborator

I haven't thought that this would be useful for non-tag inputs. Apparently it is so I've added support for it in 2.3.0 as @Glideh proposed:

  • appendNewTag -> appendNewOption
  • createTag -> createOption
  • addTagOn -> addOptionOn
  • @tag -> @option.

Old options & event will still work but new versions are encouraged from now on. Please report if you encounter any issues as this was a quite big change and even though everything seems to pass I not sure if I managed to think through all real life cases. Closing this for now.

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

3 participants