Skip to content

Instantly share code, notes, and snippets.

@the-paulus
Created September 27, 2023 07:46
Show Gist options
  • Save the-paulus/56ec000420e4c4df4f16c485b26ce311 to your computer and use it in GitHub Desktop.
Save the-paulus/56ec000420e4c4df4f16c485b26ce311 to your computer and use it in GitHub Desktop.
Demonstrates how to use a WYSIWYG editor with Livewire.

resources/js/app.js

import ClassicEditor from "@ckeditor/ckeditor5-build-classic";
ClassicEditor.create(document.querySelector('#body')).then( (editor) => {
  editor.model.document.on('change:data', (e) => {
    let componentId = Livewire.components.getComponentsByName('contact-form')[0].id
    Livewire.find(componentId).set('body', editor.getData())
  })
}).catch( (error) => {

}).finally( () => {

})

resources/views/livewire/contact-form.blade.php

<div>
  <form wire:submit.prevent="submit">
    <input type="text" wire:model.lazy="name" id="name"
    <div wire:ignore>
      <textarea class="wysiwyg" wire:model.lazy="body" class="min-h-fit h-48" name="body" id="body" wire:key="wysiwyg-body">{!! $body !!}</textarea>
    </div>
    <input type="submit">
  </form>
</div> 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment