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.

dialog_widget: Extract `get_current_values` function from `launch`.

sanchi-t2ad886f427fa
diff --git a/web/src/dialog_widget.ts b/web/src/dialog_widget.ts
index 973572c17f5..7838bf4ea48 100644
--- a/web/src/dialog_widget.ts
+++ b/web/src/dialog_widget.ts
@@ -120,6 +120,24 @@ export function close(on_hidden_callback?: () => void): void {
modals.close(current_dialog_widget_id(), {on_hidden: on_hidden_callback});
}
+export function get_current_values($inputs: JQuery): Record<string, unknown> {
+ const current_values: Record<string, unknown> = {};
+ $inputs.each(function () {
+ const property_name = $(this).attr("name")!;
+ if (property_name) {
+ if (this instanceof HTMLInputElement && this.type === "file" && this.files?.length) {
+ // If the input is a file input and a file has been selected, set value to file object
+ current_values[property_name] = this.files[0];
+ } else if (property_name === "edit_bot_owner") {
+ current_values[property_name] = $(this).find(".dropdown_widget_value").text();
+ } else {
+ current_values[property_name] = $(this).val();
+ }
+ }
+ });
+ return current_values;
+}
+
export function launch(conf: DialogWidgetConfig): string {
// Mandatory fields:
// * html_heading
@@ -176,28 +194,6 @@ export function launch(conf: DialogWidgetConfig): string {
const $submit_button = $dialog.find(".dialog_submit_button");
- function get_current_values($inputs: JQuery): Record<string, unknown> {
- const current_values: Record<string, unknown> = {};
- $inputs.each(function () {
- const property_name = $(this).attr("name")!;
- if (property_name) {
- if (
- this instanceof HTMLInputElement &&
- this.type === "file" &&
- this.files?.length
- ) {
- // If the input is a file input and a file has been selected, set value to file object
- current_values[property_name] = this.files[0];
- } else if (property_name === "edit_bot_owner") {
- current_values[property_name] = $(this).find(".dropdown_widget_value").text();
- } else {
- current_values[property_name] = $(this).val();
- }
- }
- });
- return current_values;
- }
-
if (conf.update_submit_disabled_state_on_change) {
const $inputs = $dialog.find(".modal__content").find("input,select,textarea,button");