sp-dev-fx-controls-react icon indicating copy to clipboard operation
sp-dev-fx-controls-react copied to clipboard

[ModernTaxonomyPicker] getLabelsForCurrentLanguage returns empty array

Open IRRDC opened this issue 6 months ago • 3 comments

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;

IRRDC avatar Jul 22 '25 04:07 IRRDC