Skip to content

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

Open
alexspeller wants to merge 1 commit intocibernox:masterfrom
alexspeller:alexspeller-patch-1
Open

Remove requirement to provide a search field when using multiple select#1121
alexspeller wants to merge 1 commit intocibernox:masterfrom
alexspeller:alexspeller-patch-1

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.

3 participants