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.
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
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
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 not by any chance doing Wix Editor through Safari are you as it seems to be an issue with the Preview in that browser.
See previous post for a very similar issue with another Wix User too.
https://www.wix.com/corvid/forum/community-discussion/dynamic-dataset-error-message-property-description-must-be-an-object-solved
HI givemeawhiskey, yes i’m using safari. Wow. ok i’ll check out those links and let you know how i get on
Thanks
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.
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?
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
Hi. The original issue should be resolved in Safari by now. Please try again and see if it helps.
Regards, Aleksander