[pbs-devel] [PATCH widget-toolkit 2/2] window: edit: added `convertNewlines` config

Gabriel Goller g.goller at proxmox.com
Fri Sep 15 11:46:35 CEST 2023


When setting `convertNewlines` to true, all the '\n' will
be converted to '<br>' tags and vice-versa. This means we
can press enter in a `textfieldarea`, save the config and
we get a '<br>' in the config file. When editing the value,
the '<br>' will be converted back to a '\n'.

Signed-off-by: Gabriel Goller <g.goller at proxmox.com>
---

Note: Implemented to close #4589 (support multi-line comments)

 src/window/Edit.js | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/src/window/Edit.js b/src/window/Edit.js
index 7f94e30..97cd4d2 100644
--- a/src/window/Edit.js
+++ b/src/window/Edit.js
@@ -66,6 +66,9 @@ Ext.define('Proxmox.window.Edit', {
     // onlineHelp of our first item, if set.
     onlineHelp: undefined,
 
+    // converts newlines '\n' to html '<br>' tags and vice-versa
+    convertNewlines: false,
+
     isValid: function() {
 	let me = this;
 
@@ -83,7 +86,15 @@ Ext.define('Proxmox.window.Edit', {
 
 	form.getFields().each(function(field) {
 	    if (!field.up('inputpanel') && (!dirtyOnly || field.isDirty())) {
-		Proxmox.Utils.assemble_field_data(values, field.getSubmitData());
+		let fieldData = field.getSubmitData();
+		if (me.convertNewlines) {
+		    for (let key in fieldData) {
+			if (typeof fieldData[key] === 'string' || fieldData[key] instanceof String) {
+			    fieldData[key] = fieldData[key].replaceAll('\n', '<br>');
+			}
+		    }
+		}
+		Proxmox.Utils.assemble_field_data(values, fieldData);
 	    }
 	});
 
@@ -105,7 +116,13 @@ Ext.define('Proxmox.window.Edit', {
 	        (f.id === id || f.name === id || f.dataIndex === id) && !f.up('inputpanel'),
 	    );
 	    fields.each((field) => {
+		if (me.convertNewlines) {
+		    if (typeof val === 'string' || val instanceof String) {
+			val = val.replaceAll('<br>', '\n');
+		    }
+		}
 		field.setValue(val);
+
 		if (form.trackResetOnLoad) {
 		    field.resetOriginalValue();
 		}
-- 
2.39.2






More information about the pbs-devel mailing list