settings: Fix save-discard widget fo.

The save-discard widget was not showing and hiding correctly
for the "Automated messages and emails" section in organization
settings panel. This was because the "proposed_val" was always
being returned as "undefined" for language setting as
"data-language-code", which is used to check the proposed value
of setting, was not set after changes in 36475daba7.
This commit fixes it by passing language_code value to
language_selection_widget and thus setting "data-language-code"
attribute correctly.

The changes in 36475daba7 removed language_code parameter from
language_selection_widget as it was not passed in the template
from "Display settings" section. So, this commit also passes
the language_code parameter to language_selection_widget from
"Display settings" section.
This change sets the "data-language-code" attribute even when
it is not being used there, to make sure there is no reference
to undefined fields in language_selection_widget.

Note that the above bug was reproducible only if you have not
changed the language even once and are trying to change the
other settings, as the data-language-code attribute was set
after selecting a language from the modal, but it was not
set initially after rendering the page.
This commit is contained in:
Sahil Batra 2023-07-28 15:01:24 +05:30 committed by Tim Abbott
parent 5b5ab1dbc1
commit fc5b63e5cd
4 changed files with 8 additions and 2 deletions

View File

@ -110,6 +110,7 @@ export function build_page() {
user_can_change_email: settings_data.user_can_change_email(),
user_role_text: people.get_user_type(page_params.user_id),
default_language_name: settings_display.user_default_language_name,
default_language: user_settings.default_language,
realm_push_notifications_enabled: page_params.realm_push_notifications_enabled,
settings_object: user_settings,
send_read_receipts_tooltip: $t({

View File

@ -95,6 +95,10 @@ function user_default_language_modal_post_render() {
$("#user-preferences .language_selection_widget .language_selection_button span").text(
new_language,
);
$("#user-preferences .language_selection_widget .language_selection_button span").attr(
"data-language-code",
setting_value,
);
change_display_setting(
data,

View File

@ -10,7 +10,8 @@
{{> language_selection_widget
section_name="default_language_name"
setting_value=default_language_name
section_title=settings_label.default_language_settings_label }}
section_title=settings_label.default_language_settings_label
language_code=default_language }}
{{/unless}}
<div class="input-group">

View File

@ -6,7 +6,7 @@
{{/if}}
</label>
<button type="button" class="language_selection_button button rounded small" data-section="{{section_name}}">
<span class="{{section_name}}">{{setting_value}}</span>
<span class="{{section_name}}" data-language-code="{{language_code}}">{{setting_value}}</span>
<i class="fa fa-pencil"></i>
</button>
</div>