mervick / emojionearea

Emoji Picker Plugin for jQuery
https://jsfiddle.net/mervick/1v03Lqnu/765/
MIT License
955 stars 259 forks source link

Unable to submit on keypress enter .. #443

Closed stkol76 closed 2 years ago

stkol76 commented 2 years ago

Hi :-)

I have followed the examples in issue 62 but have not been able to neigther get $('#UserSpecificMessageForm').submit(); or $('#UserSpecificMessageText').data("emojioneArea").setText(""); to work with the following code:

$("#UserSpecificMessageText").emojioneArea({
    pickerPosition: "bottom",
    tonesStyle: "radio",
    searchPlaceholder: "Søg",
    shortnames: true,
    inline: true,
    saveEmojisAs: 'shortname',     
    events: {
      keypress: function (editor, event) {
          console.log('event:keypress', event.which);
        if(event.which == 13){
          console.log('event:keypress2', event.which);
          event.preventDefault();
          $('#UserSpecificMessageForm').submit();
          $('#UserSpecificMessageText').data("emojioneArea").setText("");
        }
      }
    }
  });

I am using the latest version of emojione area downloaded from https://github.com/mervick/emojionearea today.

Can you help me? :-)

Best regards Stig :-)

mervick commented 2 years ago

Hello. When inline set to true no event triggers for enter key, because it creates new line in contenteditable, so I just ignore it in code emojionearea.js#L1469

But you can catch enter keydown by using ready event and attach addEventListener directly to editor with {useCapture: true}.

Working example here https://jsfiddle.net/mervick/b7c3sjfr/2/