Skip to content

Commit

Permalink
Merge pull request #24 from octue/fix/text-edit-mode
Browse files Browse the repository at this point in the history
FIX: crash after edit in text mode
  • Loading branch information
thclark authored Jan 22, 2024
2 parents faf3881 + 7c82639 commit cb72e09
Showing 1 changed file with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@
<script type="module">
import { JSONEditor } from '{% static "django_svelte_jsoneditor/js/svelte_jsoneditor.js" %}'

const json = JSON.parse(document.getElementById('{{ widget.attrs.id }}').value)

const editor = new JSONEditor({
target: document.getElementById('jsoneditor_{{ widget.attrs.id }}'),
props: {
content: {
json: json || undefined,
content: {
text: document.getElementById('{{ widget.attrs.id }}').value || undefined
},
onChange: (updatedContent, previousContent, { contentErrors, patchResult }) => {
document.getElementById('{{ widget.attrs.id }}').value = JSON.stringify(updatedContent.json)
onChange: (updatedContent, previousContent, { contentErrors, patchResult }) => {
const value = updatedContent.json ? JSON.stringify(updatedContent.json) : updatedContent.text
document.getElementById('{{ widget.attrs.id }}').value = value
}
}
})
Expand Down

0 comments on commit cb72e09

Please sign in to comment.