【问题标题】:Passing data to textarea inside bootstrap modal that uses TINYMCE WYSIWYG将数据传递到使用 TINYMCE WYSIWYG 的引导模式内的 textarea
【发布时间】:2017-08-28 03:48:29
【问题描述】:

我现在正在创建一个博客,我想更新评论, 我想将评论的当前数据传递给使用 TINYMCE WYSIWYG 编辑器的文本区域。

问题是如果我对 textarea 使用 tinymce,当前数据将不会显示在 textarea 上。

这是我的做法

这是触发模态的按钮:

<button type="button" class="btn btn-success btn-xs" data-toggle="modal" data-target="#myModal" data-id="{{ $comment->id }}" data-comment=" {{ $comment->comment }}"><i class="fa fa-pencil"></i></button>

这是模态

    <!--UPDATE COMMENT Modal -->
  <div class="modal fade modal-md" id="myModal" role="dialog">
    <div class="modal-dialog">

      <!-- Modal content-->
      <div class="modal-content modal-success">
      {{ Form::open(['route' => ['comments.update'], 'method' => 'PUT']) }}
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h5 class="modal-title"><b>Update Comment </b></h5>
        </div>
        <div class="modal-body">
            <div id="comment-form" class="">

                <div class="row">
                    <div class="col-md-12">
                        {!! Form::hidden('id', '', ['id' => 'comment-id']) !!}

                        {{ Form::textarea('comment', '', ['id'=>'comment-comment','class' => 'form-control', 'rows' => '3']) }}

                    </div>
                </div>

            </div>
        </div>
        <div class="modal-footer">
            <button type="submit" class="btn btn-success"><b>Update</b></button>
            <button type="button" class="btn btn-default" data-dismiss="modal"> <b>Cancel</b></button>
        </div>
        {{ Form::close() }}
      </div>
    </div>
  </div>

这是我的 js:

    <script type="text/javascript" charset="utf-8">

tinymce.init({
    selector: 'textarea',
    menubar: false,
    toolbar: false,
    statusbar:  false,
     height:     10
  });

<!--UPDATE COMMENT MODAL-->
$(function() {
    $('#myModal').on("show.bs.modal", function (e) {
         $("#comment-comment").val($(e.relatedTarget).data('comment'));
         $("#comment-id").val($(e.relatedTarget).data('id'));
    });
});

// Prevent bootstrap dialog from blocking focusin
$(document).on('focusin', function(e) {
    if ($(e.target).closest(".mce-window").length) {
        e.stopImmediatePropagation();
    }
});

$('#open').click(function() {
    $("#dialog").dialog({
        width: 800,
        modal: true
    });
});

</script>

【问题讨论】:

    标签: laravel tinymce laravel-5.3 bootstrap-modal tinymce-4


    【解决方案1】:
       {!! Form::hidden('id', $data->id , ['id' => 'comment-id']) !!}
    
       {{ Form::textarea('comment', $data->coment, ['id'=>'comment-comment','class' => 'form-control', 'rows' => '3']) }}
    

    如果您使用表单打开这种情况,您需要指定一个值,如“$data->comment”。如果您使用的是 Form 模型,则不需要指定任何值,只需添加 null 即可。检查以下链接。

    https://laravel.com/docs/4.2/html#form-model-binding

    【讨论】:

    • 是的,可以,但问题是它在模式上,我想将当前评论的值返回到使用文本编辑器的文本区域,问题是只有一种形式可以被许多 cmets 使用,当前的评论值只会在点击编辑按钮时发送到表单
    猜你喜欢
    • 2021-02-19
    • 2013-07-21
    • 2014-03-15
    • 2016-01-22
    • 1970-01-01
    • 2014-12-12
    • 2014-09-13
    • 2020-02-24
    • 1970-01-01
    相关资源
    最近更新 更多