rahmanramsi / filament-editorjs

MIT License
71 stars 27 forks source link

Field empty after reload edit page #5

Open TempleOfTemplar opened 1 year ago

TempleOfTemplar commented 1 year ago

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?

Xoshbin commented 1 year ago

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),
    ]);
}
TempleOfTemplar commented 1 year ago

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

rahmanramsi commented 1 year ago

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

Xoshbin commented 1 year ago

@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

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

Where's this code come from??

Xoshbin commented 1 year ago

@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