From 58de16460b7fbc009164c308a4cea4be73496904 Mon Sep 17 00:00:00 2001 From: Daksh Date: Sun, 26 Jan 2025 21:14:05 +0530 Subject: [PATCH 1/4] [bugfix] Preserve newline characters in input fields (#19) --- flat_json_widget/static/flat-json-widget/js/flat-json-widget.js | 2 +- .../templates/flat_json_widget/flat_json_widget.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/flat_json_widget/static/flat-json-widget/js/flat-json-widget.js b/flat_json_widget/static/flat-json-widget/js/flat-json-widget.js index 724f204..e2e5658 100644 --- a/flat_json_widget/static/flat-json-widget/js/flat-json-widget.js +++ b/flat_json_widget/static/flat-json-widget/js/flat-json-widget.js @@ -99,7 +99,7 @@ var initJsonKeyValueWidget = function(fieldName, inlinePrefix) { rows.each(function() { var inputs = $(this).find('input'), key = inputs.eq(0).val(), - value = inputs.eq(1).val(); + value = inputs.eq(1).val()?.replace(/\\n/g , '\n'); newValue[key] = value; }); diff --git a/flat_json_widget/templates/flat_json_widget/flat_json_widget.html b/flat_json_widget/templates/flat_json_widget/flat_json_widget.html index 1210fdb..a481be9 100644 --- a/flat_json_widget/templates/flat_json_widget/flat_json_widget.html +++ b/flat_json_widget/templates/flat_json_widget/flat_json_widget.html @@ -36,7 +36,7 @@

<%= label %>

<% } %> <% for(key in data){ %> - <%= _.template(django.jQuery('.flat-json-row-template-inline').eq(0).html())({ 'key': key, 'value': data[key] }) %> + <%= _.template(django.jQuery('.flat-json-row-template-inline').eq(0).html())({ 'key': key, 'value': data[key].replace('\n' , '\\n') }) %> <% } %> From b1cb19279523dc560cfbfb4f0fbac03ba403f2b1 Mon Sep 17 00:00:00 2001 From: Daksh Date: Sun, 26 Jan 2025 21:36:02 +0530 Subject: [PATCH 2/4] [bugfix] Preserve newline characters in input fields (#19) and tested --- flat_json_widget/static/flat-json-widget/js/flat-json-widget.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flat_json_widget/static/flat-json-widget/js/flat-json-widget.js b/flat_json_widget/static/flat-json-widget/js/flat-json-widget.js index e2e5658..14069fc 100644 --- a/flat_json_widget/static/flat-json-widget/js/flat-json-widget.js +++ b/flat_json_widget/static/flat-json-widget/js/flat-json-widget.js @@ -99,7 +99,7 @@ var initJsonKeyValueWidget = function(fieldName, inlinePrefix) { rows.each(function() { var inputs = $(this).find('input'), key = inputs.eq(0).val(), - value = inputs.eq(1).val()?.replace(/\\n/g , '\n'); + value = inputs.eq(1).val() && inputs.eq(1).val().replace(/\\n/g , '\n'); newValue[key] = value; }); From d34bba6640bdfd6caf70c38f28338f46b438f42a Mon Sep 17 00:00:00 2001 From: Daksh Date: Sun, 26 Jan 2025 21:42:09 +0530 Subject: [PATCH 3/4] [flat-json-widget] Preserve newline characters in input fields #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 #19 --- flat_json_widget/static/flat-json-widget/js/flat-json-widget.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flat_json_widget/static/flat-json-widget/js/flat-json-widget.js b/flat_json_widget/static/flat-json-widget/js/flat-json-widget.js index 14069fc..15793d0 100644 --- a/flat_json_widget/static/flat-json-widget/js/flat-json-widget.js +++ b/flat_json_widget/static/flat-json-widget/js/flat-json-widget.js @@ -103,7 +103,7 @@ var initJsonKeyValueWidget = function(fieldName, inlinePrefix) { newValue[key] = value; }); - // update textarea value + // update textarea value $(rawTextarea).val(JSON.stringify(newValue, null, 4)); }; From f437189979429d3d1b9d041a4ccdacde561acdea Mon Sep 17 00:00:00 2001 From: Daksh Date: Sun, 26 Jan 2025 21:45:06 +0530 Subject: [PATCH 4/4] [flat-json-widget] Preserve newline characters in input fields #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 #19 --- flat_json_widget/static/flat-json-widget/js/flat-json-widget.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flat_json_widget/static/flat-json-widget/js/flat-json-widget.js b/flat_json_widget/static/flat-json-widget/js/flat-json-widget.js index 15793d0..14069fc 100644 --- a/flat_json_widget/static/flat-json-widget/js/flat-json-widget.js +++ b/flat_json_widget/static/flat-json-widget/js/flat-json-widget.js @@ -103,7 +103,7 @@ var initJsonKeyValueWidget = function(fieldName, inlinePrefix) { newValue[key] = value; }); - // update textarea value + // update textarea value $(rawTextarea).val(JSON.stringify(newValue, null, 4)); };