fix editorjs error when the textarea is empty

This commit is contained in:
Simon Vieille 2022-04-25 14:43:33 +02:00
parent f3d5b0380d
commit 734a51891d
Signed by: deblan
GPG key ID: 579388D585F70417
2 changed files with 17 additions and 1 deletions

View file

@ -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

View file

@ -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
}