filament-editorjs icon indicating copy to clipboard operation
filament-editorjs copied to clipboard

Field empty after reload edit page

Open TempleOfTemplar opened this issue 1 year ago • 6 comments

  1. Open edit form with EditorJs field
  2. Edit something in this field
  3. Data saved into database -> ok
  4. Re-open edit form. EditorJs field is empty =(

What am i doing wrong?

TempleOfTemplar avatar Sep 15 '22 11:09 TempleOfTemplar

You have to decode it first. add it inside json_decode() method

public $body;
public function mount($id): void
{
    $this->post = Post::find($id);
    $this->form->fill([
        'body' => json_decode($this->post->body, true),
    ]);
}

Xoshbin avatar Sep 15 '22 17:09 Xoshbin

thank u very much! It would be cool if you add it to the readme)

TempleOfTemplar avatar Sep 15 '22 18:09 TempleOfTemplar

@TempleOfTemplar you can cast body field to array in model. So you don't need to modify mount method

rahmanramsi avatar Sep 16 '22 01:09 rahmanramsi

@TempleOfTemplar you can cast body field to array in model. So you don't need to modify mount method

The issue with that, when you try to render the data again with the editor js in read only mode. it's giving error.

<div
                wire:ignore
                class="editorjs-wrapper"
                x-data="editorjsreadonly({
                data: {{ $post->body }}
            })"
            >

when body is cast, you receive that message:

htmlspecialchars(): Argument #1 ($string) must be of type string, array given

Xoshbin avatar Sep 16 '22 15:09 Xoshbin

<div
                wire:ignore
                class="editorjs-wrapper"
                x-data="editorjsreadonly({
                data: {{ $post->body }}
            })"
            >

Where's this code come from??

rahmanramsi avatar Sep 19 '22 03:09 rahmanramsi

@rahmanramsi I made a read only editor.js for my websites front end it's not from your package, I'm using your package with Filament form, to save the data. then I have a separate editor.js read only to read the data. but I'm using the same approach you used to implement it in Laravel with a different id "editorjsreadonly" https://editorjs.io/configuration#read-only-mode

Xoshbin avatar Sep 19 '22 06:09 Xoshbin