Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

modal: Add support for linking the submit button to a form element.

Ganesh Pawar8908ea99ec5c
diff --git a/static/js/dialog_widget.js b/static/js/dialog_widget.js
index 5aa12f83b8a..6624941963d 100644
--- a/static/js/dialog_widget.js
+++ b/static/js/dialog_widget.js
@@ -80,6 +80,7 @@ export function launch(conf) {
// * help_link: A help link in the heading area.
// * id: Custom id to the container element to modify styles.
// * single_footer_button: If true, don't include the "Cancel" button.
+ // * form_id: Id of the form element in the modal if it exists.
for (const f of mandatory_fields) {
if (conf[f] === undefined) {
@@ -110,6 +111,14 @@ export function launch(conf) {
}
const submit_button = dialog.find(".dialog_submit_button");
+
+ // This is used to link the submit button with the form, if present, in the modal.
+ // This makes it so that submitting this form by pressing Enter on an input element
+ // triggers a click on the submit button.
+ if (conf.form_id) {
+ submit_button.attr("form", conf.form_id);
+ }
+
// Set up handlers.
submit_button.on("click", (e) => {
if (conf.loading_spinner) {
diff --git a/static/js/settings_bots.js b/static/js/settings_bots.js
index 32610272cc6..4717703df42 100644
--- a/static/js/settings_bots.js
+++ b/static/js/settings_bots.js
@@ -433,14 +433,11 @@ export function set_up() {
$(".edit_bot_form").trigger("submit");
},
post_render: edit_bot_post_render,
+ form_id: "edit_bot_form",
loading_spinner: true,
});
function edit_bot_post_render() {
- // This links the submit button to the edit bot form, so submitting this form
- // by pressing Enter on an input element triggers a click on the submit button.
- $("#edit_bot_modal .dialog_submit_button").attr("form", "edit_bot_form");
-
const avatar_widget = avatar.build_bot_edit_widget($(".edit_bot_form"));
const form = $(".edit_bot_form");
const image = li.find(".image");