Skip to content

[ModernTaxonomyPicker] getLabelsForCurrentLanguage returns empty array #2028

@IRRDC

Description

@IRRDC

Category

[ ] Enhancement

[X] Bug

[ ] Question

Version

Please specify what version of the library you are using: [3.21.0]

Observed Behavior

I noticed a crash of the DynamicForm control on my mixed language test site and traced it to the getLabelsForCurrentLanguage method of the ModernTaxonomyPicker.tsx.
After uploading some pictures to my test doc lib SharePoint added a new column called Image Tags of type TaxonomyFieldTypeMulti and assigned terms like "Screenshot". According to the data returned, the terms are labeled in German de-DE only and the only labels returned are marked as default, but the default language for the site is en-US. In the current code this will lead to no labels being found and onRenderItem to crash when accessing labels[0].name:

Image

I suggest to add more fallbacks to prevent this behavior, e.g.
let labels = item.labels.filter((name) => name.languageTag === currentLanguageTag && name.isDefault);
if (labels.length === 0) {
labels = item.labels.filter((name) => name.languageTag === currentTermStoreInfo.defaultLanguageTag && name.isDefault);
}
if (labels.length === 0) {
labels = item.labels.filter((name) => name.isDefault);
}
if (labels.length === 0) {
labels.push(item.labels[0]);
}
return labels;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions