Skip to content

Commit 1af90af

Browse files
authored
Merge pull request #5823 from akolson/fix-native_name-conundrum
Fix TypeError in LanguageDropdown when used in multiple mode
2 parents c2f2777 + 4fa95bb commit 1af90af

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

contentcuration/contentcuration/frontend/shared/views/LanguageDropdown.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@
113113
},
114114
methods: {
115115
languageText(item) {
116+
// VAutocomplete eagerly evaluates getText(internalValue) as a fallback arg to
117+
// getValue, even when that fallback isn't needed. In multiple mode, internalValue
118+
// is an Array, so languageText receives the array directly. Return early to avoid
119+
// calling .split() on undefined.
120+
if (Array.isArray(item)) {
121+
return '';
122+
}
116123
const firstNativeName = item.native_name.split(',')[0].trim();
117124
return this.$tr('languageItemText', { language: firstNativeName, code: item.id });
118125
},

contentcuration/contentcuration/frontend/shared/views/__tests__/languageDropdown.spec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,15 @@ describe('languageDropdown', () => {
8181
const item = { native_name: '', id: 'de' };
8282
expect(wrapper.vm.languageText(item)).toBe(' (de)');
8383
});
84+
85+
it('returns empty string when called with an array (multiple mode VAutocomplete internal call)', () => {
86+
const wrapper = shallowMount(LanguageDropdown, {
87+
mocks: {
88+
$tr: (key, params) => `${params.language} (${params.code})`,
89+
},
90+
});
91+
// VAutocomplete eagerly evaluates getText(internalValue) as a fallback to getValue.
92+
// In multiple mode, internalValue is an Array, so languageText receives the array.
93+
expect(wrapper.vm.languageText(['en', 'fr'])).toBe('');
94+
});
8495
});

0 commit comments

Comments
 (0)