From fe557bde77cb90058dfa75716d664111918a44be Mon Sep 17 00:00:00 2001 From: Kenneth Rodrigues Date: Tue, 23 Jul 2024 13:05:06 +0530 Subject: [PATCH] custom_profile_fields: Fix multiple modals opening. Earlier the focus remained on the button to open the modal, causing multiple modals to open on pressing enter repeatedly. This commit fixes the issue by removing the focus from the button by focusing on the first input field of the modal. --- web/src/settings_profile_fields.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/web/src/settings_profile_fields.ts b/web/src/settings_profile_fields.ts index d5b0cc18f5..5a45708a7c 100644 --- a/web/src/settings_profile_fields.ts +++ b/web/src/settings_profile_fields.ts @@ -22,6 +22,7 @@ import type {CustomProfileField} from "./state_data"; import {current_user, realm} from "./state_data"; import type {HTMLSelectOneElement, UserExternalAccountData} from "./types"; import * as ui_report from "./ui_report"; +import {place_caret_at_end} from "./ui_util"; type FieldChoice = { value: string; @@ -280,6 +281,9 @@ function open_custom_profile_field_form_modal(): void { on_click: create_profile_field, post_render: set_up_form_fields, loading_spinner: true, + on_shown() { + $("#profile_field_type").trigger("focus"); + }, }); } @@ -572,6 +576,9 @@ function open_edit_form_modal(this: HTMLElement): void { on_click: submit_form, post_render: set_initial_values_of_profile_field, loading_spinner: true, + on_shown() { + place_caret_at_end($("#id-custom-profile-field-name")[0]!); + }, }); }