Skip to content

Commit

Permalink
Handle ENTER key correctly in trigger form and allow manual JSON (apa…
Browse files Browse the repository at this point in the history
  • Loading branch information
jscheffl authored and ellisms committed Nov 13, 2024
1 parent 139ae9d commit 8de1dca
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
30 changes: 29 additions & 1 deletion airflow/www/static/js/trigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion airflow/www/templates/airflow/trigger.html
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ <h2>
<small class="text-muted">{{ dag.description[0:150] + '…' if dag.description and dag.description|length > 150 else dag.description|default('', true) }}</small>
</h2>
{{ dag_docs(doc_md, False) }}
<form method="POST" id="trigger_form" onsubmit="updateJSONconf();">
<form method="POST" id="trigger_form">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
<input type="hidden" name="dag_id" value="{{ dag_id }}">
<input type="hidden" name="origin" value="{{ origin }}">
Expand Down

0 comments on commit 8de1dca

Please sign in to comment.