custom fields: Fix exception in rendering custom profile field template.

The function `settings_account.add_custom_profile_fields_to_settings`
called twice, which resulted in two templates objects being
rendered.

The function also didn't check whether settings overlay was open or
not when processing new events, and thus would throw an "undefined"
error if a custom profile field was editing while the overlay was not
open.

Fixes #9668.
This commit is contained in:
Yashashvi Dave 2018-06-10 10:33:22 +05:30 committed by Tim Abbott
parent 51ae82fbcf
commit 40590bb6b9
4 changed files with 7 additions and 3 deletions

View File

@ -35,6 +35,7 @@ set_global('settings_emoji', {
set_global('settings_account', { set_global('settings_account', {
update_email_change_display: noop, update_email_change_display: noop,
update_name_change_display: noop, update_name_change_display: noop,
add_custom_profile_fields_to_settings: noop,
}); });
set_global('settings_display', { set_global('settings_display', {
update_page: noop, update_page: noop,

View File

@ -175,6 +175,7 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) {
case 'custom_profile_fields': case 'custom_profile_fields':
page_params.custom_profile_fields = event.fields; page_params.custom_profile_fields = event.fields;
settings_profile_fields.populate_profile_fields(page_params.custom_profile_fields); settings_profile_fields.populate_profile_fields(page_params.custom_profile_fields);
settings_account.add_custom_profile_fields_to_settings();
break; break;
case 'realm_domains': case 'realm_domains':

View File

@ -64,6 +64,11 @@ function update_user_custom_profile_fields(fields, method) {
} }
exports.add_custom_profile_fields_to_settings = function () { exports.add_custom_profile_fields_to_settings = function () {
if (!overlays.settings_open()) {
return;
}
$("#account-settings .custom-profile-fields-form").html("");
var all_custom_fields = page_params.custom_profile_fields; var all_custom_fields = page_params.custom_profile_fields;
all_custom_fields.forEach(function (field) { all_custom_fields.forEach(function (field) {

View File

@ -167,9 +167,6 @@ exports.reset = function () {
}; };
exports.populate_profile_fields = function (profile_fields_data) { exports.populate_profile_fields = function (profile_fields_data) {
$("#account-settings .custom-profile-fields-form").html("");
settings_account.add_custom_profile_fields_to_settings();
if (!meta.loaded) { if (!meta.loaded) {
return; return;
} }