advoor / nova-editor-js

Editor JS field for Laravel Nova
92 stars 54 forks source link

Error when saving the same content #74

Closed joostvanhoof closed 2 years ago

joostvanhoof commented 2 years ago

@roelofr this might be related to this issue because it's trying to save [object Object] again.

What's happening is that when I have an empty EditorJS field in Nova and type some content and save it, everything works fine.

If I then edit the resource and hit save but don't edit the content, I get:

3140 Invalid JSON text: "Invalid value." at position 1 in value for column 'post.body'. (SQL: update `posts` set `body` = [object Object], ...)

If I change the EditorJS content and save it (even if it's just adding a dot), then it does actually works.

roelofr commented 2 years ago

I still can't replicate this issue. Are you using the editor in a conditional field or something?

johnpuddephatt commented 2 years ago

I am also getting [Object object] saved in my database with 3.0.4 when updating an entry without changing the editorJs field's content.

This only happens when casting the attribute. I have the following in my model:

protected $casts = [
    "description" => NovaEditorJsCast::class,
];

If I remove this the problem goes away.

joostvanhoof commented 2 years ago

@roelofr this bug is still there for me, for you as well @johnpuddephatt? There is this commit suggested which I think should fix it?

roelofr commented 2 years ago

Fixed in v3.0.5

joostvanhoof commented 2 years ago

@roelofr this bug is still there for me. If I don't change the content (because I've edited other fields) and then update the resource I still get the error message indicating it tries to save [object Object] as a value in the database.

johnpuddephatt commented 2 years ago

@roelofr this bug is still there for me, for you as well @johnpuddephatt?

Yes it's still there in 3.0.5 when I cast the field content with Advoor\NovaEditorJs\NovaEditorJsCast. Without the casting it does not occur.

roelofr commented 2 years ago

But can you easily cast the stored data to HTML without the cast?
The mixture of HTML and JSON is supposed to be solved by the cast.