emojionearea: Can not submit form with event keypress

I cant submit a form when pressing enter in textarea. It only works when I click to somewhere, then click to the textarea and press enter. My form

<form id="add-msg-form">
        <div class="panel-footer">
            <div class="input-group" style="display: -webkit-box" id="txtbox">
                <textarea id="txtMessage" placeholder="Vui lòng nhập nội dung tin nhắn" ></textarea>
                <span class="input-group-btn">
                    <button class="btn btn-info" id="btnSend" type="submit">Send</button>
                </span>
           </div>
    </div>
</form>
$(document).ready(function() {
    $("#txtMessage").emojioneArea({
        events: {
            keypress: function (editor, event) {
                if(event.which == 13){
                    console.log('event:keypress'); //work
                        $('#add-msg-form').submit(); //not work
                                        $('#txtMessage').val(''); //not work
                                }
            },
        }
    });
});

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 20 (10 by maintainers)

Most upvoted comments

increases row in the textarea instead of returning back

use event.preventDefault() for that, example https://jsfiddle.net/1v03Lqnu/131/

how can I show the color emoji after fetching from database

use emojione for convert unicode emojis to images, first of all, install emojione, prefer installation via composer composer require emojione/emojione

next, in your php for rendering html from db

<?php

use Emojione\Emojione;
use Emojione\Client as EmojioneClient;

// your code...

$emojioneClient = new EmojioneClient();
$emojioneClient->cacheBustParam = '';
$emojioneClient->imagePathPNG = 'https://cdnjs.cloudflare.com/ajax/libs/emojione/2.1.4/assets/png/';
Emojione::setClient($emojioneClient);

$body = htmlspecialchars($field_from_db);
$body = Emojione::unicodeToImage($body);
$body = nl2br($body);

echo $body;

@mervick @lasdeparq Working perfectly in my code. Thank you very much, I hope that when you learn more you can reciprocate in some way.