ousid's avatar
Level 3

Using Trix text editor with livewire

I'm using Trix text editor and when I'm implemented on livewire I have this weird error (nothing in the console or the network tab)

trix fading|656x500

View:

  <div class="mb-4">
      <label class="block text-gray-700 text-sm text-xl font-bold mb-2" for="order">
            Page Content
       </label>
       <input id="body"
              value="Your Page Content Here"
              type="hidden"
              wire:model.debounce.365ms="form.body"
              name="content">
        <trix-editor input="body"></trix-editor>
            @error('form.body')
                <p class="text-red-700 font-semibold mt-2">
                   {{$message}}
                </p>
            @enderror
  </div>

Any Ideas?

0 likes
4 replies
ousid's avatar
ousid
OP
Best Answer
Level 3

The DOM is swapping out your input on round trip. You’ll need to use some combination of wire:ignore and moving your wire:model.

Try:


<div> <!-- top-most div don't attach livewire-->
    <div class="mb-4" wire:model.debounce.365ms="form.body" wire:ignore>
        <label class="block text-gray-700 text-sm text-xl font-bold mb-2" for="order">
            Page Content
        </label>
        <input id="body" value="Your Page Content Here" type="hidden" name="content">
        <trix-editor input="body"></trix-editor>
        @error('form.body')
        <p class="text-red-700 font-semibold mt-2">
            {{$message}}
        </p>
        @enderror
    </div>
</div>

Solved by: shortbrownman

1 like
SunnyBoy's avatar

@oussamasid Are you able to save the text with Bold Italics and all those bells and whistles that come with the Trix coz for me nothing works except it all saves as a plain text. So I see no point of using a wysiwyg editor rather plain textarea tag which works fine! LOL

Let me know if work for you!

1 like
SunnyBoy's avatar

Oh it worked but I switched to Medium Editor instead later! 😊

Thanks!

Please or to participate in this conversation.