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.
This commit is contained in:
Sahil Batra 2022-08-22 16:55:42 +05:30 committed by Tim Abbott
parent 1990a1ff99
commit 1da7086c35
1 changed files with 12 additions and 4 deletions

View File

@ -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")