From 1da7086c35d14752a0ab5e1e9c794b213c6b2b38 Mon Sep 17 00:00:00 2001 From: Sahil Batra Date: Mon, 22 Aug 2022 16:55:42 +0530 Subject: [PATCH] settings: Fix save button being disabled even for valid values. On changing either one of message edit or delete limit setting from "Any time" to "Custom", the "Save changes" button is not enabled even after entering valid input. We can see this bug if both the edit or delete limit setting is set to "Anytime" initially and one of the setting is changed to "Custom". This is because the custom input for "Any time" case is empty even though it is hidden and the check for disabling the button was not checking whether the input is hidden or not. This commit changes the code to consider the value in custom input box only if the input is visible, i.e. the dropdown value is set to "Custom". This bug was introduced in #21837 where we added the functionality to disable the save button. --- static/js/settings_org.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/static/js/settings_org.js b/static/js/settings_org.js index fba5aed900..b68089f4d8 100644 --- a/static/js/settings_org.js +++ b/static/js/settings_org.js @@ -1258,11 +1258,19 @@ export function build_page() { 10, ); + const msg_edit_limit_dropdown_value = $("#id_realm_msg_edit_limit_setting").val(); + const edit_limit_custom_value_invalid = + msg_edit_limit_dropdown_value === "custom_limit" && + (edit_limit_value <= 0 || Number.isNaN(edit_limit_value)); + + const msg_delete_limit_dropdown_value = $("#id_realm_msg_delete_limit_setting").val(); + const delete_limit_custom_value_invalid = + msg_delete_limit_dropdown_value === "custom_limit" && + (delete_limit_value <= 0 || Number.isNaN(delete_limit_value)); + const disable_save_btn = - edit_limit_value <= 0 || - delete_limit_value <= 0 || - Number.isNaN(edit_limit_value) || - Number.isNaN(delete_limit_value); + edit_limit_custom_value_invalid || delete_limit_custom_value_invalid; + $(e.target) .closest(".org-subsection-parent") .find(".subsection-changes-save button")