ID25 / rails_emoji_picker

Add emoji to your app :smiley_cat:
143 stars 41 forks source link

What's about sending a message by pressing enter key? #2

Closed ghost closed 8 years ago

ghost commented 8 years ago

Hi, ID25! Great job and great tool that worked really out from the box. I have one little question: with data attributes like in example <%= f.text_field :content, class: 'form-control', data: { emojiable: true } %> i can't send a message by pressing enter key like we usually do it with form_for, only by pressing submit button. Is it how it works?

ghost commented 8 years ago

Okay, i got it. maybe it will be helpful to someone. if you want to handle submit on enter key, the easiest way to make something like this:

<%= form_for Message.new do |f| %>
    <p class="emoji-picker-container">
        <%= f.text_field :content, class: 'form-control', data: { emojiable: true } %>
    </p>
<% end %>
<script type="text/javascript">
    $(document).ready(function() {
        $('div[contenteditable]').keydown(function(e) {
            if (e.keyCode === 13) {
                // your stuff
                return false;
            }
        });
    });
</script>