Hi, I have searched for a solution and tried a few things for a while now, but I can’t resolve this error. Also, please know that I’m new to coding. That said, I’m learning and appreciative of any and all guidance.
- I need to display the first and last names of people in one text box that is located inside of a Repeater. I found this tutorial to calculate fields in Wix’s help documents. I combed over the code for an embarrassingly long time, but I can’t execute what I need. One line of code shows an error ‘item’ is not defined.
export function RecipientDataset_afterQuery(item, context) {
item.fullName = item.firstName + " " + item.lasstName;
return item;
}
$w.onReady(function () {
$w("#repeater1").onItemReady( ($item, itemData, index) => {
$item("#repeaterFullName").text = item.fullName;
} );
} );
Thank you for any assistance!
Hi!
That’s the kind of code you would need to use (disregard other lines that are extra functionality):
So basically you would populate your text element in repeater with this line:
$item("#text5").text = itemData.firstName + " " + itemData.lastName;
Also just to add, if you go back to your linked example page from Wix.
https://support.wix.com/en/article/corvid-tutorial-calculating-and-displaying-collection-data
You will notice that the example they give you, that you have used in the top part of your code, actually needs to be placed in the data.js file in your backend and not on your page.
You can add a hook to a collection by clicking on Hooks in the Content Manager’s menu. After choosing which hooks you want to register, skeletal code will be added to a file named data.js in your site’s Backend for each hook you selected.
// In file backend/data.js
export function Employees_afterQuery(item, context) {
item.fullName = item.lastName + ", " + item.firstName;
item.age = ageFromDob(item.dob);
return item;
}
However, for yourself and ease of use and unless you are going to have a full name field saving it in your dataset too.
Then just use the code on your page like Yevheniia has shown you to combine the two fields into the one text string for your full name.