Skip to content

Commit

Permalink
Fix invalid input data error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Michaël St-Georges committed Mar 13, 2024
1 parent 30284e3 commit 89c2478
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "json-editor",
"version": "1.1.4",
"version": "1.1.5",
"description": "JSON Editor (based on https://github.com/josdejong/svelte-jsoneditor)",
"license": "MIT",
"svelte": "index.js",
Expand Down
16 changes: 10 additions & 6 deletions src/Component.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
fieldType,
defaultValue,
false,
validationText,
fieldType === 'text' ? validationText : undefined,
formStep
);
Expand All @@ -71,7 +71,7 @@
value = JSON.parse(fieldState.value);
}
catch (err) {
contentErrors = err.toString();
errors = err.toString();
}
}
Expand All @@ -88,21 +88,25 @@
unsubscribe?.();
})
function handleChange(updatedContent, previousContent, { contentErrors, patchResult }) {
function handleChange(updatedContent, previousContent, opts) {
let value;
if (!opts) {
opts = {};
}
if (typeof updatedContent.text !== 'undefined') {
try {
value = JSON.parse(updatedContent.text);
}
catch (err) {
contentErrors = err.toString();
opts.contentErrors = err.toString();
}
}
else {
value = updatedContent.json;
}
if (!contentErrors) {
if (!opts.contentErrors) {
if (fieldType === 'text') {
fieldApi.setValue(JSON.stringify(value))
}
Expand All @@ -111,7 +115,7 @@
}
}
errors = contentErrors;
errors = opts.contentErrors;
}
</script>

Expand Down

0 comments on commit 89c2478

Please sign in to comment.