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

Remove requirement to provide a search field when using multiple select #1121

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

alexspeller
Copy link

This field is not actually required, if you don't use it, you don't get the search filled in again when you press delete but that's not actually a problem if you dont' need that

@cibernox
Copy link
Owner

cibernox commented Jun 3, 2018

This assertion is becase 99% of the time if someone hits is because they forgot about the field, not because they don't want to delete with backspace.

I'd recommend that if you want to prevent deleting items with backspace you take an approach like the one in this twiddle: https://ember-twiddle.com/ad9bb34985ea8f072069dcea733d5eb9?openFiles=controllers.application.js%2C

tl;dr: Add an onkeydown=fn that does if (e.keyCode === 8 && e.target.value === "") return false

@mayatron
Copy link
Contributor

Thanks @cibernox for this tip. I used this to modify the behavior for {{power-select-multiple}} to allow backspace to completely remove the previous selection via an onkeydown function.

onKeyDown(api, e) {
  if (e.keyCode === 8 && isBlank(e.target.value)) {
    const lastSelection = api.selected[api.selected.length - 1];
    api.actions.select(api.selected.without(lastSelection));
    return false;
  }

  return true;
}

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

Successfully merging this pull request may close these issues.

None yet

3 participants