diff --git a/frontend_tests/node_tests/templates.js b/frontend_tests/node_tests/templates.js index 24c28ae235..6ec213dd29 100644 --- a/frontend_tests/node_tests/templates.js +++ b/frontend_tests/node_tests/templates.js @@ -610,8 +610,8 @@ function render(template_name, args) { var field = {name: "GitHub user name", id: 2, hint: "Or link to profile"}; var args = {field: field, field_value: "@GitHub", field_type: "text"}; var html = render('custom-user-profile-field', args); - assert.equal($(html).find('input').attr('id'), 2); - assert.equal($(html).find('input').val(), "@GitHub"); + assert.equal($(html).attr('id'), 2); + assert.equal($(html).find('.custom_user_field_value').val(), "@GitHub"); assert.equal($(html).find('.field_hint').text(), "Or link to profile"); assert.equal($(html).find('label').text(), "GitHub user name"); }()); diff --git a/static/js/settings_account.js b/static/js/settings_account.js index cfde5319c2..bb60077434 100644 --- a/static/js/settings_account.js +++ b/static/js/settings_account.js @@ -61,11 +61,23 @@ exports.add_custom_profile_fields_to_settings = function () { var type; var value = people.my_custom_profile_data(field.id); var is_long_text = field_type === "Long Text"; + var is_choice_field = field_type === "Choice"; + var field_choices = []; if (field_type === "Long Text" || field_type === "Short Text") { type = "text"; } else if (field_type === "Choice") { type = "choice"; + var field_choice_dict = JSON.parse(field.field_data); + for (var choice in field_choice_dict) { + if (choice) { + field_choices[field_choice_dict[choice].order] = { + value: choice, + text: field_choice_dict[choice].text, + selected: choice === value, + }; + } + } } else if (field_type === "Date") { type = "date"; } else if (field_type === "URL") { @@ -82,6 +94,8 @@ exports.add_custom_profile_fields_to_settings = function () { field_type: type, field_value: value, is_long_text_field: is_long_text, + is_choice_field: is_choice_field, + field_choices: field_choices, }); $("#account-settings .custom-profile-fields-form").append(html); }); @@ -313,12 +327,12 @@ exports.set_up = function () { $("#deactivate_self_modal").modal("show"); }); - $(".custom_user_field input, .custom_user_field textarea").on('change', function () { + $(".custom_user_field_value").on('change', function () { var fields = []; var value = $(this).val(); + fields.push({id: parseInt($(this).parent().attr("id"), 10), value: value}); var spinner = $("#custom-field-status").expectOne(); loading.make_indicator(spinner, {text: 'Saving ...'}); - fields.push({id: parseInt($(this).attr("id"), 10), value: value}); settings_ui.do_settings_change(channel.patch, "/json/users/me/profile_data", {data: JSON.stringify(fields)}, spinner); }); diff --git a/static/templates/settings/custom-user-profile-field.handlebars b/static/templates/settings/custom-user-profile-field.handlebars index 2cdf4d64c4..8ca3d529a0 100644 --- a/static/templates/settings/custom-user-profile-field.handlebars +++ b/static/templates/settings/custom-user-profile-field.handlebars @@ -1,9 +1,20 @@ -
+
{{#if is_long_text_field}} - + {{else}} - + {{#if is_choice_field }} + + {{else}} + + {{/if}} {{/if}}
{{ field.hint }}