question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

select same item will set its value to null

See original GitHub issue

I see in your documents demo, when you repeat select the same value, the option will not be deselected, but when I use this plugin, it will deselect this same option.

I see in your source code there is a logic if (this.isOptionSelected(option)) this.deselect(option). I don’t want this behavior, I just want to keep the selected option if user select the same option in the dropdown list

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:9
  • Comments:15 (4 by maintainers)

github_iconTop GitHub Comments

20reactions
adi518commented, Jan 26, 2018

Hah, our QA halt upon this for the exact same reason. This behavior shouldn’t be enabled by default IMO.

I dissected @msyesyan PR into an extended component of vue-select as a temporary workaround, which absolves source intervention. I did however, set toggleSelectOption default value to false. Make sure your Vue version supports composition with the extends property.

Edit: added disabled prop as well. You’ll need to style it though.

<script>
// ExtendedVueSelect.vue
// https://github.com/sagalbot/vue-select/issues/180
// https://github.com/sagalbot/vue-select/pull/194
import vSelect from 'vue-select'

export default {
  extends: vSelect,
  methods: {
    /**
     * Select a given option.
     * @param  {Object|String} option
     * @return {void}
     */
    select(option) {
      if (this.isOptionSelected(option)) {
        if (this.toggleSelectOption) {
          this.deselect(option)
        }
      } else {
        if (this.taggable && !this.optionExists(option)) {
          option = this.createOption(option)
        }
        if (this.multiple && !this.mutableValue) {
          this.mutableValue = [option]
        } else if (this.multiple) {
          this.mutableValue.push(option)
        } else {
          this.mutableValue = option
        }
      }
      this.onAfterSelect(option)
    },
    /**
     * Toggle the visibility of the dropdown menu.
     * @param  {Event} e
     * @return {void}
     */
    toggleDropdown(e) {
      if (!this.disabled) {
        if (e.target === this.$refs.openIndicator || e.target === this.$refs.search || e.target === this.$refs.toggle || e.target === this.$el) {
          if (this.open) {
            this.$refs.search.blur() // dropdown will close on blur
          } else {
            this.open = true
            this.$refs.search.focus()
          }
        }
      }
    },
  },
  props: {
    /**
     * Enable/Disable deselect the option by double select it
     * @type {Boolean}
     */
    toggleSelectOption: {
      type: Boolean,
      default: false
    },
    /**
     * Enable/Disable
     * @type {Boolean}
     */
    disabled: {
      type: Boolean,
      default: false
    }
  }
}
</script>
3reactions
sagalbotcommented, Sep 4, 2018

This is fixed in the latest v.2.5.0 release.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to set select option value to null in Angular 2
I can't use [ngValue] on the default options; it just gives me a value of 0: null (string). And skip setting value results...
Read more >
How to set NULL value to items when a region is selected
I want to set the value of the select list of Region 1 (item P1_SELECT_1) to NULL value when I click on the...
Read more >
Message Sets: TDS Null handling options - IBM
TDS supports the handling of null values within messages, provided that the logical Nillable property of the element is set.
Read more >
Everything you wanted to know about $null - PowerShell
$null is an automatic variable in PowerShell used to represent NULL. You can assign it to variables, use it in comparisons and use...
Read more >
B.3.4.3 Problems with NULL Values - MySQL :: Developer Zone
The concept of the NULL value is a common source of confusion for newcomers to SQL, who often think that NULL is the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found