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

Uncaught error on backspace #937

Closed
NoahStahl opened this issue Mar 3, 2019 · 7 comments
Closed

Uncaught error on backspace #937

NoahStahl opened this issue Mar 3, 2019 · 7 comments

Comments

@NoahStahl
Copy link

NoahStahl commented Mar 3, 2019

Steps to reproduce

  1. Go to https://vue-multiselect.js.org/ (as example, same occurs in my project)
  2. Open dev tools
  3. Place cursor into example input.
  4. Press backspace.
  5. Observe error in console: Uncaught TypeError: Cannot read property '$isDisabled' of undefined

Expected behaviour

Backspace ignored if no value

Actual behaviour

Error in console.

image

@juanpscotto
Copy link

I have the same error

@shentao shentao added the bug label Mar 3, 2019
@shentao
Copy link
Owner

shentao commented Mar 3, 2019

Thanks for reporting! Gonna work on this in a few days unless someone wants to pick this up :)

@phlegx
Copy link
Contributor

phlegx commented Mar 6, 2019

Found the line multiselectMixin.js#L602. Option is undefined and should be checked first. The undefined option comes from here multiselectMixin.js#L635.

phlegx added a commit to phlegx/vue-multiselect that referenced this issue Mar 6, 2019
@Alex-Sokolov
Copy link

@shentao hi! Can you say when planned release with this fix?

@dgriego
Copy link

dgriego commented Mar 24, 2019

hey, @NoahStahl, @juanpscotto, @phlegx, @Alex-Sokolov, and @shentao a long story short, I solved the issue for me by utilizing the blockKeys prop like so

multiselect(
   v-model="value"
  :options="options"
  :block-keys="['Delete']"
)

search for blockKeys here http://localhost:8080/#sub-props

How I found this was I followed the errors to the removeLastElement function. I saw here a function guard utilizing blockKeys to prevent the Delete key from triggering removeElement, but this is not the default value, so when the drop-down is active, and you hit the escape key, a search action will trigger.

This results in this.internalValue[this.internalValue.length - 1] evaluating to undefined, since the array is empty, hence why option is undefined.

    removeLastElement () {
      /* istanbul ignore else */
      if (this.blockKeys.indexOf('Delete') !== -1) return
      /* istanbul ignore else */
      if (this.search.length === 0 && Array.isArray(this.internalValue) {
        this.removeElement(this.internalValue[this.internalValue.length - 1], false)
      }
    }

It's seems reasonable to set ['Delete'] as a default value to blockKeys or always return when the escape key is pressed as it doesnt' seem to serve any purpose when searching or selecing anyways (as far as I can tell at least).

    /**
     * Array of keyboard keys to block
     * when selecting
     * @default 1000
     * @type {String}
    */
    blockKeys: {
      type: Array,
      default () {
        return ['Delete']
      }
    }

anyways, I hope this helps :)

@juanpscotto
Copy link

@dgriego Thanks man!! I tried that trick you said and it works well!. Thanks for the help.

@jackkoppa
Copy link

Thanks for PR #939, @phlegx 👍 Looking forward to the patch

@shentao shentao closed this as completed Apr 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants