Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

YuMp's avatar
Level 2

TinyMCE does not load data to update comment using wire:ignore

Hi, I'm trying to load a comment's data to update using tinymce but it comes up empty, does anyone have any idea what I'm doing wrong? when I remove tinymce the data loads but I need tinycme to format the comments.

Thanks in advance. UPDATE: I am able to successfully edit but. however, the comment date is not displayed. It simply goes blank. After editing the new edition is displayed successfully, I'm having trouble loading the old text data so I can edit the comment. Does anyone have any idea what could be wrong?

code-->

                <div>
                    <div class="mb-2" wire:ignore>
                        <label class="block font-medium text-sm text-gray-700" for="page-text-editor">Edit Comment</label>
                        <textarea x-ref="editComment" wire:model.defer="body" name="post" cols="30" rows="4" class="page_text w-full bg-gray-100 rounded-xl border-none placeholder-gray-900 text-sm px-4 py-2" 
                               x-data
                               x-init="
                                       tinymce.init({
                                            path_absolute: '/',
                                            selector: 'textarea.page_text',
                                            plugins: [
                                                 'advlist autolink lists link image charmap print preview hr anchor pagebreak',
                                                  'searchreplace wordcount visualblocks visualchars code fullscreen ',
                                                  'insertdatetime media nonbreaking save table directionality',
                                                  'emoticons template paste textpattern  imagetools help  '
                                                   ],
                                                    toolbar: 'insertfile undo redo | styleselect | bold italic forecolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image media | help ',
                                                    relative_urls: false,
                                                    remove_script_host : false,
                                                    document_base_url: '{{config('app.url')}}/',
                                                    language: 'pt_BR',
                                                    setup: function (editor) {
                                                            editor.on('init change', function () {
                                                                      editor.save();
                                                              });
                                                   editor.on('change', function (e) {
                                                            @this.set('body', editor.getContent());
                                                    });
                                                     },
                                                     });
                                                    ">
                           </textarea>
                   </div>
                </div>

Livewire edit comment

class EditComment extends Component { public Comment $comment; public $body;

protected $rules = [
    'body' => 'required|min:4',
];

protected $listeners = ['setEditComment'];

public function setEditComment($commentId)
{
    $this->comment = Comment::findOrFail($commentId);
    $this->body = $this->comment->body;

    $this->emit('editCommentWasSet');
}

public function updateComment()
{
    if (auth()->guest() || auth()->user()->cannot('update', $this->comment)) {
        abort(Response::HTTP_FORBIDDEN);
    }

    $this->validate();

    $this->comment->body = $this->body;
    $this->comment->save();

    $this->emit('commentWasUpdated', 'Comment was updated!');
}

public function render()
{
    return view('livewire.edit-comment');
}

}

0 likes
4 replies
vincent15000's avatar
Level 63

I had such a problem with CKEditor, perhaps the solution will help you.

I've had to wrap the textarea (ckeditor flag for ckeditor) inside a div.

1 like
YuMp's avatar
Level 2

@vincent15000 Yes, I saw this in a search but every way I try to wrap it in a div to be the root-element, it doesn't work because at least it's editing, it's just not showing the old text.

If you have any ideas by analyzing my code and can make a suggestion I would be grateful. Thanks again and have a great day.

1 like
vincent15000's avatar

@YuMp Oh sorry I don't have any other idea because I don't use TinyMCE. Perhaps I will have some time to test your code, then I tell you something, but not sure ;).

1 like
YuMp's avatar
Level 2

@vincent15000 Okay thank you. When you have some time available, if possible, take a look. Thanks a lot in advance.

1 like

Please or to participate in this conversation.