Passing data to textarea inside bootstrap modal that uses TINYMCE WYSIWYG
I am creating a blog now and I want to update a comment, I want to pass the current data of the comment to the textarea that uses TINYMCE WYSIWYG editor.
The problem is if I use tinymce for the textarea the current data will NOT show on the textarea.
here is how I do it
This is the button that will trigger the modal:
<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>
This is the modal
    <!--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">×</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>
here is my 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>
   {!! Form::hidden('id', $data->id , ['id' => 'comment-id']) !!}
   {{ Form::textarea('comment', $data->coment, ['id'=>'comment-comment','class' => 'form-control', 'rows' => '3']) }}
If you are using form open that case you need to specify a value like "$data->coment". And if you are using Form model that case it's not required to specify any value just need to add null. Check below link.
https://laravel.com/docs/4.2/html#form-model-binding
链接地址: http://www.djcxy.com/p/61480.html