Since it’s a repeater, you’ll have to use onItemReady():
$w("#repeate1").onItemReady( ($item, itemData, index) => {
$item("#conacatText").text = `${itemData.fieldKey1}-${itemData.fieldKey2}-${itemData.fieldKey3}`;
//use your actual element id and field keys
}
Thank you for your quick reply. Your code works perfectly when the fields source is coming from a field from a collection but in my case the field labels to display come from ‘Reference’ fields.
I have two collections ‘Items’ & ‘Sub-Categories’ linked each others by 3 ‘Reference’ fields ‘Category1’ - ‘Category2’ - ‘Category3’
//code....
.then( (results) => {
$w("#repeater1").data = results.items;
})
///....
$w("#repeater1").onItemReady( ($item, itemData, index) => {
$item("#concatText").text = `${itemData.referenceField1.fieldKey1}-${itemData.referenceField2.fieldKey2}-${itemData.referenceField2.fieldKey1}`;
//instead of "referenceField" use the key of the reference field, instead of "fieldKey" use the field key as appears in the original collection
}
@domivax as I can see in your screenshot above, some of your records don’t have the reference value, and that’s why you’re getting these errors.
To get rid of these error, you’ll need to modify your code:
@jonatandor35 I am so sorry but I still have the error message. I just realized that the three categories must be filled out to have a good concatenate string and no error message but items can have only one category. In case of only one category, ‘category1’ is always filled out first, 2 categories = ‘category1’ & ‘category2’ are always filled out.
I thought somethings like that:
//code
if (itemData.category2.subCategoryLabel === null) {$item(“#TextSubCategoryConcatenate”).text = ${itemData.category1.subCategoryLabel};}
else if (itemData.category3.subCategoryLabel === null) {$item(“#TextSubCategoryConcatenate”).text = ${itemData.category1.subCategoryLabel} – ${itemData.category2.subCategoryLabel};}
@domivax
! stands for not.
!itemData.category2 is like writing itemDataCategory2 === false;
If itemData.category2.subCategoryLabel doesn’t exist its Boolean value is false.
Now let’s do it in another way that probably will be better in your case:
//...code
let texts = [];
let concatText = "";
if (itemData.category1.subCategoryLabel){//that means if the value exist
texts.push(itemData.category1.subCategoryLabel);
}
if (itemData.category2.subCategoryLabel){
texts.push(itemData.category2.subCategoryLabel);
}
if (itemData.category3.subCategoryLabel){
texts.push(itemData.category3.subCategoryLabel);
}
if (texts.length > 0) {
concatText = texts.join(" – ");
}
$item("#TextSubCategoryConcatenate").text = concatText;
//code