Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] Input fields does not respect newlines #19

Open
pandafy opened this issue Aug 2, 2022 · 19 comments · May be fixed by #32
Open

[bug] Input fields does not respect newlines #19

pandafy opened this issue Aug 2, 2022 · 19 comments · May be fixed by #32

Comments

@pandafy
Copy link
Member

pandafy commented Aug 2, 2022

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
@anurag629
Copy link

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

@pandafy
Copy link
Member Author

pandafy commented Nov 21, 2022

@anurag629 were you able to replicate the issue locally?

@anurag629
Copy link

anurag629 commented Nov 21, 2022

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

@anurag629
Copy link

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

@nemesifier
Copy link
Member

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

@anurag629
Copy link

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

@pandafy
Copy link
Member Author

pandafy commented Nov 23, 2022

@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
Copy link

anurag629 commented Nov 23, 2022

@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

@pandafy
Copy link
Member Author

pandafy commented Nov 23, 2022

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

@anurag629
Copy link

anurag629 commented Nov 23, 2022

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

@nemesifier
Copy link
Member

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

@himanshuc3
Copy link

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

@pandafy
Copy link
Member Author

pandafy commented Jan 17, 2023

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

@himanshuc3
Copy link

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

@pandafy
Copy link
Member Author

pandafy commented Jan 17, 2023

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

@himanshuc3
Copy link

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

@himanshuc3
Copy link

Hey @pandafy Persisting with the same blocker unfortunately.

@mrgear111
Copy link

hey @pandafy i want to work upon this issue!

@pandafy
Copy link
Member Author

pandafy commented Jan 21, 2025

You can go ahead @mrgear111

mrgear111 added a commit to mrgear111/django-flat-json-widget that referenced this issue Jan 26, 2025
mrgear111 added a commit to mrgear111/django-flat-json-widget that referenced this issue Jan 26, 2025
mrgear111 added a commit to mrgear111/django-flat-json-widget that referenced this issue Jan 26, 2025
…sp#19

Fixed an issue where newline characters () in input fields were removed when saving via the HTML form. Updated the logic to ensure newline characters are preserved in both display and saved data.

Fixed openwisp#19
mrgear111 added a commit to mrgear111/django-flat-json-widget that referenced this issue Jan 26, 2025
…sp#19

Fixed an issue where newline characters () in input fields were removed when saving via the HTML form. Updated the logic to ensure newline characters are preserved in both display and saved data.

Fixes openwisp#19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment