django-flat-json-widget
django-flat-json-widget copied to clipboard
[bug] Input fields does not respect newlines
Steps to replicate
- Using the raw JSON mode, enter the following data which contains a newline character (
\n)
{
"var1": "line1\nline2",
}
- Save the object
- Edit the flat JSON widget, using the HTML form and add a new field
key: var2
value: line3
Expected outcome
- The newline character is shown in the input field
- The newline character is present in the data
Actual outcome
- The newline character is removed from the value of
var1field upon saving the data using the HTML form
Hey, I want to work on this issue. I am new here. Need guidance in order to resolve this issue. Thanks!
@anurag629 were you able to replicate the issue locally?
@pandafy I completed the setup but was not able to find out the endpoint where I should write JSON values.
After creating testapp and model with 'name' field I added the given example code in admins.py file. Is I am doing correct ?
@anurag629 follow the instructions to run the dev server locally and open the browser to log into the admin interface, navigate to the add form page of JsonDocument and you will find the widget.
@nemesisdesign I checked in locally. I found that the string in 'Raw JSON Editing' looks fine but in output, it removes '\n'. We can save it as a raw string.
@anurag629 we have to make sure that the value of the string does not change while changing from Raw JSON Editing to form input. Only using the Raw JSON Editing is not the fix here.
We have to find out what is removing the newline character \n from the input. By following the steps mention in the issue description, you should be able to replicate the bug.
@anurag629 we have to make sure that the value of the string does not change while changing from
Raw JSON Editingto form input. Only using theRaw JSON Editingis not the fix here.We have to find out what is removing the newline character
\nfrom the input. By following the steps mention in the issue description, you should be able to replicate the bug.
@pandafy I replicated the issue.
Where do I have to find out, in this repo or in enwisp-radius means in which repo backend is written?

The bug is definitely in this repository only. I would start looking from https://github.com/openwisp/django-flat-json-widget/blob/master/flat_json_widget/static/flat-json-widget/js/flat-json-widget.js
@pandafy In the given link line 51 we are parsing JSON using JSON.parse() and this function removes all the escape sequencing characters from JSON. In place of JSON.parse() we can use JSON.stringify() then it will not exclude the escape characters.
https://github.com/openwisp/django-flat-json-widget/blob/master/flat_json_widget/static/flat-json-widget/js/flat-json-widget.js#L51
Am I correct?
@anurag629 aren't JSON.parse() and JSON.stringify() two methods performing opposite operations? How can we substitute one with the other? I don't think that's a solution, have you already tried it?
Hey there @pandafy I was trying to reproduce the issue. I was able to boot up the server and login to the admin interface. What I am stuck on is finding the route path for jsondocument. P.S. New to python/django, so might test your patience a bit
@himanshuc3 after starting the development server, visit this URL http://127.0.0.1:8000/admin/test_app/jsondocument/
shows 404 error. Attached a screenshot

@himanshuc3 how are you running the test project? Did you follow these instructions ?
Followed everything till launching a server. Admin portal works at /admin but admin/test_app/jsondocument/ route doesn't work.
Hey @pandafy Persisting with the same blocker unfortunately.