Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle ENTER key correctly in trigger form and allow manual JSON #42525

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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