diff --git a/CHANGELOG.md b/CHANGELOG.md index c2e6eb4..e8f9be8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * add allowed chars in RouteParameterSlugify and CodeSlugify ### Fixed * fix creation of new element when a menu is edited +* fix editorjs error when the textarea is empty ### Changed ## [1.14.0] - 2022-04-20 diff --git a/src/core/Resources/assets/js/modules/editorjs.js b/src/core/Resources/assets/js/modules/editorjs.js index a5e9dcf..b7fd984 100644 --- a/src/core/Resources/assets/js/modules/editorjs.js +++ b/src/core/Resources/assets/js/modules/editorjs.js @@ -147,9 +147,24 @@ const doInitEditor = () => { editorContainer.attr('id', id) element.hide() + let data = [] + + try { + const value = JSON.parse(element.val()) + + if (Array.isArray(value)) { + data = value + } + } catch (e) { + } + + if (!Array.isArray(data)) { + data = [] + } + const editor = new EditorJS(buildConfiguration({ holder: id, - data: JSON.parse(element.val()), + data: data, onReady: () => { ready = true }