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

Selecting an element submits form #325

Open
ausminternet opened this issue Aug 12, 2015 · 2 comments
Open

Selecting an element submits form #325

ausminternet opened this issue Aug 12, 2015 · 2 comments

Comments

@ausminternet
Copy link

Hi there,

I have a form with a hidden field and an contenteditable div. I bound the enter-key to the contenteditable, to put it's text to the hidden filed and submit the form.

Now on selecting an element from the atwho.js dropdown with the enter-key will insert the atwho.js element AND submit the form. Any ideas how to prevent the enter to submit the form, when it was used to select from atwho list?

@pavelivanov
Copy link

I think developers need to add tabindex="" to dropdown list, focus it on visible and focus field back when hide.
But now I did this:

var viewJustHid = false;
$element.on('hidden.atwho', function() {
    viewJustHid = true;
    setTimeout(function() {
        viewJustHid = false;
    }, 100);
});

$element.on('keydown', function(event) {
    if (event.which == 13 && !event.shiftKey && !event.ctrlKey && !event.metaKey) {
        event.preventDefault();

        if (!viewJustHid) {
            submit();
        }
    }
});

@DDaems
Copy link

DDaems commented Aug 17, 2015

This is how i resolved it: http://jsbin.com/gabuwetowu/edit?html,console,output
Its nearly the same as grammka his one, only i use the isSelecting event to check if the user is doing a @ mention. I think i prefer grammka his one, and might change my solution so i can drop my keyuplistener.

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

3 participants