简体   繁体   English

如何将 emojioneArea(独立)select 值添加到文本字段? JQuery 导轨 6.0.0

[英]How to add emojioneArea (stand-alone) select value to text field? JQuery Rails 6.0.0

I'm trying to add the emoji value from the stand alone emoji-picker to a text input (same effect as having the emojipicker on the input itself).我正在尝试将表情符号值从独立的表情符号选择器添加到文本输入(与在输入本身上使用表情符号选择器效果相同)。 I tried getting the value from the emojibtn_click event, but it returns undefined for the value that returns.我尝试从 emojibtn_click 事件中获取值,但它返回未定义的返回值。 How can I selected an emoji through the stand alone emojipicker and transfer the value to a text input field with the same result as using the normal input?如何通过独立的表情符号选择器选择表情符号并将值传输到文本输入字段,结果与使用普通输入的结果相同?

new.html.erb新.html.erb

<div style="overflow: hidden;">
  <%= form.text_field :content, placeholder: 'Type your message....', id: "conversation_comment_content_#{@conversation.id}", style: 'width: 100% !important; border-radius: 0 !important; height: 36px;' %>
</div>

javascript javascript

  <script>
    $(document).ready(function() {

        $('#trigger').emojioneArea({
            standalone: true,
            autocomplete: false,
            events: {
               emojibtn_click: function (button, event) {
                   console.log('event:emojibtn.click, emoji=' + button.children().data("name"))
               },
                change: function(editor, event) {
                   console.log('event:change');
                }
            }
        })
    });

  </script>

I turned the emojioneArea component into a reusable object and then captured its values.我将 emojioneArea 组件变成了一个可重复使用的 object,然后捕获了它的值。

$(document).ready(function() {
      var emojiStandAlone =  $('#trigger').emojioneArea({
            standalone: true,
            autocomplete: false,
            events: {
            }
        })

        const emojionearea = emojiStandAlone[0].emojioneArea

        emojionearea.on('picker.hide', function() {
            const emoji = emojionearea.getText()
            emojionearea.setText('')
            if(emoji) {
                $("#conversation_comment_content_<%= @conversation.id %>").val(function(i, val) {
                    return val + `${emoji}`;
                });
            }
        });

    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM