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

Enter to submit form, example code not working #1409

Closed
3 tasks done
eugenio11 opened this issue Nov 14, 2024 · 1 comment
Closed
3 tasks done

Enter to submit form, example code not working #1409

eugenio11 opened this issue Nov 14, 2024 · 1 comment

Comments

@eugenio11
Copy link

Prerequisites

  • I am running the latest version
  • I checked the documentation and found no answer
  • I checked to make sure that this issue has not already been filed

Explanation

Your code example to allow using ENTER for form submitting

tagify.on('keydown', onTagifyKeyDown);

function onTagifyKeyDown(e) {
  // Check if 'e' is a KeyboardEvent
  if (e instanceof KeyboardEvent) {
    if (e.key === 'Enter' &&        // "enter" key pressed
        !tagify.state.inputText &&   // assuming user is not in the middle of adding a tag
        !tagify.state.editing) {     // user not editing a tag
      // Add a small delay to ensure Tagify has finished processing before submitting
      setTimeout(() => formElm.submit(), 0); // Use 0ms to allow the event loop to process
    }
  }
}
  • What is the expected behavior?

  • What is happening instead?

e.key is undefined

I need to use e.detail.event.key instead (google Chrome 130.0.6723.117)

@yairEO
Copy link
Owner

yairEO commented Nov 23, 2024

Sorry about that. the code should be: e.detail.event.key and not e.key

@yairEO yairEO closed this as completed Nov 23, 2024
yairEO added a commit that referenced this issue Nov 23, 2024
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

2 participants