From e9316499cbf6e4765e7faefec819732a487a4071 Mon Sep 17 00:00:00 2001 From: Sahil Batra Date: Mon, 31 Oct 2022 23:19:07 +0530 Subject: [PATCH] settings_org: Pass subsection elem to get_subsection_property_elements. We passed subsection elem to get_subsection_property_elements function in all cases except the one when calling from discard button click handler and we passed the input elem instead in that case. This commit changes the code to pass subsection element directly in the discard button click handler as well such that we can use get_subsection_property_elements function for the stream settings code and do not find the subsection element inside the function. --- frontend_tests/node_tests/settings_org.js | 2 -- static/js/settings_org.js | 8 ++++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/frontend_tests/node_tests/settings_org.js b/frontend_tests/node_tests/settings_org.js index e7194dd114..a6fe8176ac 100644 --- a/frontend_tests/node_tests/settings_org.js +++ b/frontend_tests/node_tests/settings_org.js @@ -169,7 +169,6 @@ function test_submit_settings_form(override, submit_form) { $invite_to_realm_policy_elem.data = () => "number"; let $subsection_elem = $(`#org-${CSS.escape(subsection)}`); - $subsection_elem.closest = () => $subsection_elem; $subsection_elem.set_find_results(".prop-element", [ $bot_creation_policy_elem, $email_address_visibility_elem, @@ -207,7 +206,6 @@ function test_submit_settings_form(override, submit_form) { $realm_default_language_elem.data = () => "string"; $subsection_elem = $(`#org-${CSS.escape(subsection)}`); - $subsection_elem.closest = () => $subsection_elem; $subsection_elem.set_find_results(".prop-element", [$realm_default_language_elem]); submit_form(ev); diff --git a/static/js/settings_org.js b/static/js/settings_org.js index 4381a5f973..5e42148f5b 100644 --- a/static/js/settings_org.js +++ b/static/js/settings_org.js @@ -197,9 +197,8 @@ export function extract_property_name($elem, for_realm_default_settings) { return /^id_(.*)$/.exec($elem.attr("id").replace(/-/g, "_"))[1]; } -function get_subsection_property_elements(element) { - const $subsection = $(element).closest(".org-subsection-parent"); - return Array.from($subsection.find(".prop-element")); +function get_subsection_property_elements(subsection) { + return Array.from($(subsection).find(".prop-element")); } const simple_dropdown_properties = [ @@ -957,7 +956,8 @@ export function register_save_discard_widget_handlers( $container.on("click", ".subsection-header .subsection-changes-discard button", (e) => { e.preventDefault(); e.stopPropagation(); - for (const elem of get_subsection_property_elements(e.target)) { + const $subsection = $(e.target).closest(".org-subsection-parent"); + for (const elem of get_subsection_property_elements($subsection)) { discard_property_element_changes(elem, for_realm_default_settings); } const $save_btn_controls = $(e.target).closest(".save-button-controls");