2017-08-28 5 views
1

私は今ブログを作成しています。コメントを更新したいです。 TINYMCE WYSIWYGエディタを使用するテキストエリアにコメントの現在のデータを渡したいとします。TINYMCE WYSIWYGを使用するブートストラップモーダル内のテキストエリアにデータを渡す

問題は、現在のデータがテキストエリアに表示されないテキストエリアにtinymceを使用する場合です。ここ

これは、モーダルをトリガーするボタンである私はそれを行う方法

です:

<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> 

答えて

0
{!! Form::hidden('id', $data->id , ['id' => 'comment-id']) !!} 

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

フォームを開いている場合は、 "$ data-> coment"のような値を指定する必要があります。その場合、Formモデルを使用している場合は、値を指定する必要はなく、nullを追加するだけです。以下のリンクを確認してください。

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

+0

はい、それはすることができますが、問題はそれがモーダルであると私は、テキストエディタを使用してテキストエリアに現在のコメントの値を返すようにしたいですし、問題が一つだけのフォームがあるありますこれは多くのコメントで使用できますが、現在のコメント値は編集ボタンをクリックするとフォームに送信されます –

関連する問題