Hi i believe i have copied the code that Wix provided for an after query. I have saved code in a backend file and also the remaining code on the actual page i would like the element to display first and last name on. Please help, what am i missing?
I have used this code from the tutorial.
https://support.wix.com/en/article/corvid-tutorial-calculating-and-displaying-collection-data
so i the backend i have copied and pasted this code
// In file backend/data.js export function Employees_afterQuery(item, context) { item.fullName = item.lastName + "," + item.firstName; return item; }
// question. Do i need to use the exact field names in my collection for the last name and first name fields to work?
do i also need to insert some code between the quotation marks ?
and on the page i would like this code to show first and last name within a text element, i have copied and pasted this code
$w.onReady(function() { $w("#dataset1").onReady(() => { populateCalculatedFields(); } ); $w("#dataset1").onCurrentIndexChanged( (index) => { populateCalculatedFields(); } ); } ); function populateCalculatedFields() { const currentItem = $w("#dataset1").getCurrentItem(); $w("#textFullName").text = currentItem.fullName; } //#textFullName is the name of my text element and this has been assigned in the properties panel
// dataset1 is the dataset that appears on the actual page
your help is greatly appreciated as i have no coding experience
Thanks
Adam
ok, i'm completely stuck. Is there someone who can work through the original code because this really is stopping any progression
Thanks in advance
Loading the code for my page. To debug this code, open ta1h9.js in Developer Tools.
[Dataset - Populated] 'TextData' collection into element '#input1': {...}
[Dataset - Populated] 'TextData' collection into element '#input3': {...}
[Dataset - Populated] 'TextData' collection into element '#input5': {...}
[Dataset - Populated] 'TextData' collection into element '#input2': {...}
[Dataset - Populated] 'TextData' collection into element '#input4': {...}
[Dataset - Populated] 'TextData' collection into element '#input6': {...}
[Dataset - Populated] 'TextData' collection into element '#button2': {...} this did save and redirect before, so have no idea why this is happening?
Hi i cannot actually check my live site because the button links to the next page will not redirect and firefox browser won't let me continue at all, a new issue but starting to be frustrating.
HI givemeawhiskey, yes i'm using safari. Wow. ok i'll check out those links and let you know how i get on
Thanks
Thanks, i have checked my field keys and updated accordingly.
Can you tell if the code i have pasted would actually work? I have the following error message in the console
TypeError: Property description must be an object.
which is the second line of code in this snippet
$w.onReady(function() { $w("#dataset1").onReady(() => {
Thanks
Adam
You are best suited making your dataset fields the same as what is in the tutorial or as the basic name that Wix would use for it, like First Name (firstName) and Last Name (lastName), as that way you wouldn't have to change anything in the code.
However, yes the .lastName and .firstName needs to match the field keys in your dataset to begin with, although they don't need to be changed from how they are written in the code, simply change it to match your field keys for them both.
If you wanted to display it in a table of a repeater, then it also clearly shows you how to easily do that too.
https://support.wix.com/en/article/corvid-tutorial-calculating-and-displaying-collection-data#table
https://support.wix.com/en/article/corvid-tutorial-calculating-and-displaying-collection-data#repeater