diff --git a/airflow/www/static/js/trigger.js b/airflow/www/static/js/trigger.js index 2ded629240146..7a3444f460f41 100644 --- a/airflow/www/static/js/trigger.js +++ b/airflow/www/static/js/trigger.js @@ -96,6 +96,33 @@ function updateJSONconf() { jsonForm.setValue(JSON.stringify(params, null, 4)); } +/** + * If the user hits ENTER key inside an input, ensure JSON data is updated. + */ +function handleEnter() { + updateJSONconf(); + // somehow following is needed to enforce form is submitted correctly from CodeMirror + document.getElementById("json").value = jsonForm.getValue(); +} + +/** + * Track user changes in input fields, ensure JSON is updated when user presses enter + * See https://github.com/apache/airflow/issues/42157 + */ +function enterInputField() { + const form = document.getElementById("trigger_form"); + form.addEventListener("submit", handleEnter); +} + +/** + * Stop tracking user changes in input fields + */ +function leaveInputField() { + const form = document.getElementById("trigger_form"); + form.removeEventListener("submit", handleEnter); + updateJSONconf(); +} + /** * Initialize the form during load of the web page */ @@ -148,7 +175,8 @@ function initForm() { } else if (elements[i].type === "checkbox") { elements[i].addEventListener("change", updateJSONconf); } else { - elements[i].addEventListener("blur", updateJSONconf); + elements[i].addEventListener("focus", enterInputField); + elements[i].addEventListener("blur", leaveInputField); } } } diff --git a/airflow/www/templates/airflow/trigger.html b/airflow/www/templates/airflow/trigger.html index 71d09e79076f1..7cdcd337beddf 100644 --- a/airflow/www/templates/airflow/trigger.html +++ b/airflow/www/templates/airflow/trigger.html @@ -163,7 +163,7 @@

{{ dag.description[0:150] + '…' if dag.description and dag.description|length > 150 else dag.description|default('', true) }}

{{ dag_docs(doc_md, False) }} -
+