Skip to content

Conversation

mrgear111
Copy link

@mrgear111 mrgear111 commented Jan 26, 2025

[flat-json-widget] Preserve newline characters in input fields (#19)

Description:

This PR fixes an issue where newline characters (\n) in input fields were being removed upon saving data through the HTML form. The logic has been updated to ensure that newline characters are preserved correctly in both the display and the saved data.

Fixes #19

Checklist:

  • I have followed the OpenWISP contribution guidelines.
  • I have manually tested the changes proposed in this pull request.

Testing:

  • Verified that newline characters are retained in the input fields when editing and saving data via the HTML form.

This is my first time creating a PR, and I was trying to follow your contribution guidelines. I mistakenly committed four times, but the main fix is in the first commit. Please review it.

…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
…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
@mrgear111 mrgear111 changed the title [flat-json-widget] Preserve newline characters in input fields #19 Fixed an issue where newline characters (\n) 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 #19 [flat-json-widget] Preserve newline characters in input fields. Issue where newline characters (\n) 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 #19 Jan 26, 2025
Copy link

@KanishkRanjan KanishkRanjan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The input tag in HTML removes special characters like \n, which was the root cause of this bug. This behavior has now been handled correctly.

@KanishkRanjan
Copy link

@nemesifier can we please merge this?

@mrgear111
Copy link
Author

@nemesifier Can you please review this!

@pandafy pandafy moved this from In progress to Needs review in OpenWISP Contributor's Board Mar 7, 2025
@pandafy pandafy self-requested a review March 7, 2025 10:39
@mrgear111 mrgear111 closed this Oct 9, 2025
@github-project-automation github-project-automation bot moved this from Needs review to Done in OpenWISP Contributor's Board Oct 9, 2025
@nemesifier nemesifier reopened this Oct 9, 2025
@nemesifier nemesifier changed the title [flat-json-widget] Preserve newline characters in input fields. Issue where newline characters (\n) 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 #19 [fix] Preserve newline characters in input fields #19 Oct 9, 2025
@nemesifier nemesifier added the bug Something isn't working label Oct 9, 2025
@github-project-automation github-project-automation bot moved this to Backlog in 25.09 Release Oct 9, 2025
Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sorry but we got carried away with other activites with @openwisp and forgot to review this PR.

After looking at this solution, my question is: has anyone understood what causes the bug in the first place?

@github-project-automation github-project-automation bot moved this from Done to In progress in OpenWISP Contributor's Board Oct 9, 2025
@KanishkRanjan
Copy link

KanishkRanjan commented Oct 9, 2025

Yes, I tried checking what happens when you use the \n character inside an input tag ( I don't remember properly but it was some related input or textarea ).
It simply gets removed, and if I remember correctly, the code updated the data based on the value from the input box — where the \n was already stripped out, so the newline was effectively removed.

@KanishkRanjan
Copy link

KanishkRanjan commented Oct 9, 2025

So his solution simply adds \\n instead of \n, ensuring it is treated as a regular string rather than a special character, as reflected in the file changes.

@nemesifier nemesifier moved this from Backlog to In progress in 25.09 Release Oct 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: In progress
Status: In progress
Development

Successfully merging this pull request may close these issues.

[bug] Input fields does not respect newlines
3 participants