From b27c8fc7551235cae4adbc16644bec4c85f269d7 Mon Sep 17 00:00:00 2001 From: Daksh Date: Fri, 10 Oct 2025 18:24:09 -0300 Subject: [PATCH] [fix] Ensured input fields preserve new lines #19 Fixes #19 --- .../static/flat-json-widget/js/flat-json-widget.js | 4 ++++ .../templates/flat_json_widget/flat_json_widget.html | 2 +- 2 files changed, 5 insertions(+), 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 bfacfb9..2645ae9 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 @@ -100,6 +100,10 @@ var initJsonKeyValueWidget = function (fieldName, inlinePrefix) { var inputs = $(this).find("input"), key = inputs.eq(0).val(), value = inputs.eq(1).val(); + // normalize UI representation of \\n fo \n + if (value) { + value = value.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..24b5df5 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/g , "\\n") }) %> <% } %>