This is an automated email from the ASF dual-hosted git repository.

eladkal pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new f86e3a1cf7 fix: save codemirror content to extra textarea (#32893)
f86e3a1cf7 is described below

commit f86e3a1cf722edfe0e470b5ac9aa5b981d81d777
Author: Gene Hynson <[email protected]>
AuthorDate: Tue Aug 1 01:50:58 2023 -0700

    fix: save codemirror content to extra textarea (#32893)
    
    * fix: save codemirror content to textarea
---
 airflow/www/static/js/connection_form.js | 32 +++++++++++++++++---------------
 1 file changed, 17 insertions(+), 15 deletions(-)

diff --git a/airflow/www/static/js/connection_form.js 
b/airflow/www/static/js/connection_form.js
index 453be58411..03043a2abd 100644
--- a/airflow/www/static/js/connection_form.js
+++ b/airflow/www/static/js/connection_form.js
@@ -202,6 +202,21 @@ $(document).ready(() => {
     $("form#model_form div.well.well-sm button:submit")
   );
 
+  // Change conn.extra TextArea widget to CodeMirror
+  const textArea = document.getElementById("extra");
+  const editor = CodeMirror.fromTextArea(textArea, {
+    mode: { name: "javascript", json: true },
+    gutters: ["CodeMirror-lint-markers"],
+    lineWrapping: true,
+    lint: true,
+  });
+
+  // beautify JSON
+  const jsonData = editor.getValue();
+  const parsedData = JSON.parse(jsonData);
+  const formattedData = JSON.stringify(parsedData, null, 2);
+  editor.setValue(formattedData);
+
   /**
    * Changes the connection type.
    * @param {string} connType The connection type to change to.
@@ -296,6 +311,8 @@ $(document).ready(() => {
         // payload.
         if (this.name === "extra") {
           let extra;
+          // save the contents of the CodeMirror editor to the textArea
+          editor.save();
           try {
             extra = JSON.parse(this.value);
           } catch (e) {
@@ -353,19 +370,4 @@ $(document).ready(() => {
 
   // Initialize the form by setting a connection type.
   changeConnType(connTypeElem.value);
-
-  // Change conn.extra TextArea widget to CodeMirror
-  const textArea = document.getElementById("extra");
-  const editor = CodeMirror.fromTextArea(textArea, {
-    mode: { name: "javascript", json: true },
-    gutters: ["CodeMirror-lint-markers"],
-    lineWrapping: true,
-    lint: true,
-  });
-
-  // beautify JSON
-  const jsonData = editor.getValue();
-  const data = JSON.parse(jsonData);
-  const formattedData = JSON.stringify(data, null, 2);
-  editor.setValue(formattedData);
 });

Reply via email to