custom_profile_fields: Initialize typeahead for every pronoun field.

Fixes #29921.
Before this, we used to initialize only 1 typeahead resulting in the bug
of only the first field updating even when trying to change values in the
others.

Co-authored-by: Ngadou Yopa <ngadou.y@turing.com>
This commit is contained in:
Shubham Padia 2024-07-01 11:14:35 +00:00 committed by Tim Abbott
parent 5ef14c3a8e
commit ba05e8eeac
1 changed files with 26 additions and 22 deletions

View File

@ -189,26 +189,30 @@ export function initialize_custom_date_type_fields(element_id: string): void {
} }
export function initialize_custom_pronouns_type_fields(element_id: string): void { export function initialize_custom_pronouns_type_fields(element_id: string): void {
const commonly_used_pronouns = [ $(element_id)
$t({defaultMessage: "he/him"}), .find<HTMLInputElement>(".pronouns_type_field")
$t({defaultMessage: "she/her"}), .each((_index, pronoun_field) => {
$t({defaultMessage: "they/them"}), const commonly_used_pronouns = [
]; $t({defaultMessage: "he/him"}),
const bootstrap_typeahead_input = { $t({defaultMessage: "she/her"}),
$element: $(element_id).find<HTMLInputElement>("input.pronouns_type_field"), $t({defaultMessage: "they/them"}),
type: "input" as const, ];
}; const bootstrap_typeahead_input = {
new Typeahead(bootstrap_typeahead_input, { $element: $(pronoun_field),
items: 3, type: "input" as const,
helpOnEmptyStrings: true, };
source() { new Typeahead(bootstrap_typeahead_input, {
return commonly_used_pronouns; items: 3,
}, helpOnEmptyStrings: true,
sorter(items, query) { source() {
return bootstrap_typeahead.defaultSorter(items, query); return commonly_used_pronouns;
}, },
highlighter_html(item) { sorter(items, query) {
return typeahead_helper.render_typeahead_item({primary: item}); return bootstrap_typeahead.defaultSorter(items, query);
}, },
}); highlighter_html(item) {
return typeahead_helper.render_typeahead_item({primary: item});
},
});
});
} }