django-flat-json-widget icon indicating copy to clipboard operation
django-flat-json-widget copied to clipboard

[bug] Input fields does not respect newlines

Open pandafy opened this issue 3 years ago • 19 comments

Steps to replicate

  1. Using the raw JSON mode, enter the following data which contains a newline character (\n)
{
    "var1": "line1\nline2",
}
  1. Save the object
  2. 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 var1 field upon saving the data using the HTML form

pandafy avatar Aug 02 '22 14:08 pandafy

Hey, I want to work on this issue. I am new here. Need guidance in order to resolve this issue. Thanks!

anurag629 avatar Nov 20 '22 18:11 anurag629

@anurag629 were you able to replicate the issue locally?

pandafy avatar Nov 21 '22 08:11 pandafy

@pandafy I completed the setup but was not able to find out the endpoint where I should write JSON values.

anurag629 avatar Nov 21 '22 13:11 anurag629

After creating testapp and model with 'name' field I added the given example code in admins.py file. Is I am doing correct ?

anurag629 avatar Nov 21 '22 14:11 anurag629

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

nemesifier avatar Nov 21 '22 23:11 nemesifier

@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 avatar Nov 22 '22 19:11 anurag629

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

pandafy avatar Nov 23 '22 09:11 pandafy

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

@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? Screenshot from 2022-11-23 01-11-33 Screenshot from 2022-11-23 01-11-40

anurag629 avatar Nov 23 '22 12:11 anurag629

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 avatar Nov 23 '22 13:11 pandafy

@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 avatar Nov 23 '22 16:11 anurag629

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

nemesifier avatar Nov 23 '22 17:11 nemesifier

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 avatar Jan 17 '23 04:01 himanshuc3

@himanshuc3 after starting the development server, visit this URL http://127.0.0.1:8000/admin/test_app/jsondocument/

pandafy avatar Jan 17 '23 10:01 pandafy

shows 404 error. Attached a screenshot Screenshot from 2023-01-17 16-52-08

himanshuc3 avatar Jan 17 '23 11:01 himanshuc3

@himanshuc3 how are you running the test project? Did you follow these instructions ?

pandafy avatar Jan 17 '23 12:01 pandafy

Followed everything till launching a server. Admin portal works at /admin but admin/test_app/jsondocument/ route doesn't work.

himanshuc3 avatar Jan 17 '23 13:01 himanshuc3

Hey @pandafy Persisting with the same blocker unfortunately.

himanshuc3 avatar Jan 23 '23 13:01 himanshuc3