yairEO / tagify

🔖 lightweight, efficient Tags input component in Vanilla JS / React / Angular / Vue
https://yaireo.github.io/tagify/
Other
3.55k stars 436 forks source link

Enter to submit form, example code not working #1409

Open eugenio11 opened 1 week ago

eugenio11 commented 1 week ago

Prerequisites

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
    }
  }
}

e.key is undefined

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