Skip to content
This repository has been archived by the owner on Oct 2, 2019. It is now read-only.

Pressing enter for selection of a dropdown value directly submits form #862

Closed
razam217 opened this issue Apr 17, 2015 · 8 comments
Closed

Comments

@razam217
Copy link

I am working with ui-select, and whenever I press enter to select some searched results, the result is selected and the form directly goes on to submit. I cant figure it out, what is the problem.

Here is the HTML I'm using

<ui-select ng-model="$parent.selectedPatient"
                                    theme="select2"
                                    reset-search-input="true"
                                    title="Select Patient">
                                    <ui-select-match allow-clear="true"     placeholder="Select Patient">{{$select.selected['Patient.name']['HumanName.text']}}</ui-select-    match>
                                    <ui-select-choices repeat="patient['@id'] as patient in patients track by $index"
                                        refresh="refreshPatients($select.search)"
                                        refresh-delay="0">
                                        <div ng-bind-html="patient['Patient.name']['HumanName.text'] | highlight: $select.search"></div>
                                    </ui-select-choices>
                                    </ui-select>
@knifesk
Copy link

knifesk commented Apr 20, 2015

Having the same issue.... will look into it later.

@razam217
Copy link
Author

Hi @knifesk,
I have found a solution, I was using <button>, and the default type of button is submit, so I had to specify the type="button", and the issue fixed....

Reference: https://github.com/gregurco/ui-select/commit/673369ce8b906fa2da610e887a9611f90a15351e

@knifesk
Copy link

knifesk commented Apr 21, 2015

Yes I know.. but when you're pressing enter key in the search field the form should not be sent.. your solution removes the possibility of submitting the form with the enter key... even if you are in another field, because the form has no default action and can only submitted by mouse or tabbing to the button and pressing enter.

@loverajoel
Copy link
Contributor

Hey guys this pr solve this issue #868

@knifesk
Copy link

knifesk commented Apr 22, 2015

You're awesome! Thanks for testing it and creating the tests for it

@mtraynham
Copy link

Same bug as #808?

@knifesk
Copy link

knifesk commented Apr 22, 2015

In part.. this bug does not contemplate ESC key, only fixes the behaviour with ENTER key... @loverajoel, in the condition you can compare if the key is KEY.ESC, also, to fix that issue too..

if (key === KEY.ENTER || key === KEY.ESC) {

that should do the trick

@brianfeister
Copy link

@loverajoel is @knifesk's comment about KEY.ESC valid in your opinion? If you think so, can you push that change to your PR?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants