You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
options.onChange = function () {
var json = editor.get();
textarea.value=JSON.stringify(json);
}
The above piece of code has nasty behavior. According to json-editor docs, editor.get() throws an Exception when the editor doesn't contain a valid JSON value. Well, what are the implications? It saves the last valid JSON value. Few open issues are due to this behavior. For instance consider, #26 On the second attempt when clearing completely (assuming CTRL + A and Backspace), onChange triggers, and editor.get() throws exception failing to update widget.value. #47 The last known value in textarea.value is "", copy-pasting invalid json does not update its value due to the same reasons mentioned.
Possible Solution:
Changing <script> block in django_json_widget.html
Django's inbuilt form validation takes care of validating JSON text.
Hackaround (just in case changes doesn't reach code-base)
Define JSONFieldWidget as follow:
"""django_json_widget.widgets.JSONEditorWidget with custom template_name"""
from django_json_widget.widgets import JSONEditorWidget
class JSONFieldWidget(JSONEditorWidget):
template_name = 'widgets/json_field_widget.html'
Define json_field_widget.html in the templates/widgets folder as follow:
That is it! Use JSONFieldWidget in place of JSONEditorWidget
The text was updated successfully, but these errors were encountered:
m0hithreddy
changed the title
Suggestion to use get/SetText() instead of get/set()
Suggestion to use get/SetText() instead of get/set() to avoid weird save/error issues
Sep 26, 2021
m0hithreddy
changed the title
Suggestion to use get/SetText() instead of get/set() to avoid weird save/error issues
Suggestion to use get/setText() instead of get/set() to avoid weird save/error issues
Sep 26, 2021
The above piece of code has nasty behavior. According to json-editor docs, editor.get() throws an Exception when the editor doesn't contain a valid JSON value. Well, what are the implications? It saves the last valid JSON value. Few open issues are due to this behavior. For instance consider, #26 On the second attempt when clearing completely (assuming CTRL + A and Backspace), onChange triggers, and editor.get() throws exception failing to update widget.value. #47 The last known value in textarea.value is "", copy-pasting invalid json does not update its value due to the same reasons mentioned.
Possible Solution:
Changing <script> block in django_json_widget.html
Django's inbuilt form validation takes care of validating JSON text.
Hackaround (just in case changes doesn't reach code-base)
Define JSONFieldWidget as follow:
Define json_field_widget.html in the templates/widgets folder as follow:
That is it! Use JSONFieldWidget in place of JSONEditorWidget
The text was updated successfully, but these errors were encountered: