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

PowerSelectMultipleWithCreate triggers a form submit on enter #95

Open
makepanic opened this issue Nov 19, 2019 · 1 comment
Open

PowerSelectMultipleWithCreate triggers a form submit on enter #95

makepanic opened this issue Nov 19, 2019 · 1 comment

Comments

@makepanic
Copy link

makepanic commented Nov 19, 2019

It seems like using PowerSelectMultipleWithCreate inside a form with a submit listener will trigger the submit action when using the Enter key.

This doesn't seem to happen when wrapping a regular PowerSelectWithCreate with the form.

e.g. in the dummy app:

<form {{on 'submit' (action onFormSubmit)}}>
  <PowerSelectMultipleWithCreate
    @options={{countries}}
    @searchField="name"
    @selected={{selectedCountries}}
    @onChange={{action (mut selectedCountries)}}
    @onCreate={{action "createCountry"}} as |country|
  >
    {{country.name}}
  </PowerSelectMultipleWithCreate>
</form>

triggers the onFormSubmit method to be called when pressing the enter key.

I'm currently trying to trigger the Enter in a failing test but it's somewhat complicated 🤔

Seems like manually pressing Enter triggers a submit event on the form element.
If I do it via triggerKeyEvent() it doesn't work.
20191119-161132

edit: It seems like the issue is that Multiple adds the input inline while the other one places the search input into the dropdown wormhole.

edit2: It seems like this is the expected behavior for any input inside a form element.
@cibernox do you think it would be a good idea to prevent the enter event inside the power-select trigger from bubbling up?

@makepanic
Copy link
Author

It seems like there's already Enter handling in power-select:

https://github.com/cibernox/ember-power-select/blob/master/addon/components/power-select-multiple.js#L49

If i add e.preventDefault(); near the e.stopPropagation(); it works as expected.

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

1 participant