Skip to content

Commit

Permalink
fix 29655
Browse files Browse the repository at this point in the history
  • Loading branch information
Sar-thak-3 committed May 10, 2024
1 parent 643998f commit d6fa653
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions web/src/dialog_widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import _ from "lodash";

import render_dialog_widget from "../templates/dialog_widget.hbs";

import type {AjaxRequestHandler} from "./channel";
import {$t_html} from "./i18n";
import type { AjaxRequestHandler } from "./channel";
import { $t_html } from "./i18n";
import * as loading from "./loading";
import * as modals from "./modals";
import * as ui_report from "./ui_report";
Expand Down Expand Up @@ -100,7 +100,7 @@ export function show_dialog_spinner(): void {

// Supports a callback to be called once the modal finishes closing.
export function close(on_hidden_callback?: () => void): void {
modals.close("dialog_widget_modal", {on_hidden: on_hidden_callback});
modals.close("dialog_widget_modal", { on_hidden: on_hidden_callback });
}

export function launch(conf: DialogWidgetConfig): void {
Expand Down Expand Up @@ -135,8 +135,8 @@ export function launch(conf: DialogWidgetConfig): void {
// has scrollable content. Default behaviour is to hide the scrollbar when it is
// not in use.

const html_submit_button = conf.html_submit_button ?? $t_html({defaultMessage: "Save changes"});
const html_exit_button = conf.html_exit_button ?? $t_html({defaultMessage: "Cancel"});
const html_submit_button = conf.html_submit_button ?? $t_html({ defaultMessage: "Save changes" });
const html_exit_button = conf.html_exit_button ?? $t_html({ defaultMessage: "Cancel" });
const html = render_dialog_widget({
heading_text: conf.html_heading,
link: conf.help_link,
Expand All @@ -155,6 +155,7 @@ export function launch(conf: DialogWidgetConfig): void {
}

const $submit_button = $dialog.find(".dialog_submit_button");
const $dialog_form = $dialog.find('.modal__content');

function get_current_values($inputs: JQuery): Record<string, unknown> {
const current_values: Record<string, unknown> = {};
Expand Down Expand Up @@ -203,6 +204,29 @@ export function launch(conf: DialogWidgetConfig): void {
$submit_button.attr("form", conf.form_id);
}

// Set up handlers by Sarthak
$dialog_form.on("keydown", (e) => {
if (e.keyCode != 13) {
return
}
e.preventDefault();

if ($submit_button.prop("disabled")) {
return;
}

if (conf.validate_input && !conf.validate_input(e)) {
return;
}
if (conf.loading_spinner) {
show_dialog_spinner();
} else if (conf.close_on_submit) {
close();
}
$("#dialog_error").hide();
conf.on_click(e);
})

// Set up handlers.
$submit_button.on("click", (e) => {
e.preventDefault();
Expand Down Expand Up @@ -240,7 +264,7 @@ export function submit_api_request(
url: string,
data: Omit<Parameters<AjaxRequestHandler>[0]["data"], "undefined">,
{
failure_msg_html = $t_html({defaultMessage: "Failed"}),
failure_msg_html = $t_html({ defaultMessage: "Failed" }),
success_continuation,
error_continuation,
}: RequestOpts = {},
Expand Down

0 comments on commit d6fa653

Please sign in to comment.