Live site was working fine on Friday. Yesterday, users got error 500 page. Following this, repeaters start showing the original template (“I’m Whiskers” rather than populated with data). I have reported this to Customer Care but have not had any answer yet. Wondering if others have had this happen, and since I am a (very) amateur coder, if it is my fault somehow. Advice?
Did you make any change to your code or other relevant parts of your site?
How are you populating your Repeaters? Dataset? Code? If you are using code, please show us here - nicely formatted in a code block - so we can assist.
Hi, Yisrael, thanks for answering.
The repeaters are populated by a dataset, but I also use code. It is clunky. I’m sure it could be written cleaner. The error comes when button9 is clicked. It should bring up a particular “worksheet” for the particular participant. This has worked fine for weeks, but no longer.
import wixUsers from ‘wix-users’ ;
import wixData from ‘wix-data’ ;
import wixLocation from ‘wix-location’ ;
$w . onReady ( function () {
// Write your JavaScript here
$w ( “#dataset2” ). onReady (() => {
$w ( “#repeater1” ). onItemReady (( $item , itemData , index ) => {
let aptitle = itemData . title ;
let user = wixUsers . currentUser ;
let userId = user . id ; //
let isLoggedIn = user . loggedIn ; // true
let userRole = user . role ; // “Member”
user . getEmail ()
. then (( email ) => {
let userEmail = email ;
console . log ( userEmail );
console . log ( userId );
wixData . query ( “participantworksheets” )
. eq ( “title” , userEmail )
. eq ( “aPtitleref” , aptitle )
. find ()
. then (( results ) => {
if ( results . length == 0 ) {
let toSave = {
“title” : userEmail ,
“aPtitleref” : aptitle ,
};
wixData . save ( “participantworksheets” , toSave )
. catch ( ( err ) => {
let errorMsg = err ;
} );
}
})
});
})
});
$w ( “#dataset2” ). onReady (() => {
$w ( “#repeater1” ). onItemReady (( $item , itemData , index ) => {
// …
let aptitle = itemData . title ;
let user = wixUsers . currentUser ;
let userId = user . id ; //
let isLoggedIn = user . loggedIn ; // true
let userRole = user . role ; // “Member”
user . getEmail ()
. then (( email ) => {
let userEmail = email ; //
console . log ( userEmail );
console . log ( userId );
$w ( “#repeater1” ). forEachItem ( ( $item , itemData , index ) => {
let APname = $item ( “#text13” ). text ;
wixData . query ( “participantworksheets” )
. eq ( “title” , userEmail )
. eq ( "aPtitleref" , APname )
. find ()
. then (( results ) => {
if ( results . items . length > 0 ) {
let partitem = results . items [ 0 ];
let begun = partitem . begun ;
if ( begun === true ) {
$item ( “#button9” ). label = “Continue Writing” ;
$item ( “#checkbox1” ). checked = true ;
}
}
} )
} )
})
})
})
$w ( “#dataset2” ). onReady (() => {
$w ( “#repeater1” ). onItemReady (( $item , itemData , index ) => {
// …
let aptitle = itemData . title ;
let user = wixUsers . currentUser ;
let userId = user . id ; //
let isLoggedIn = user . loggedIn ; // true
let userRole = user . role ; // “Member”
user . getEmail ()
. then (( email ) => {
let userEmail = email ; // “user@something.com”
console . log ( userEmail );
console . log ( userId );
$w ( “#repeater1” ). forEachItem ( ( $item , itemData , index ) => {
let APname = $item ( “#text13” ). text ;
wixData . query ( “participantworksheets” )
. eq ( “title” , userEmail )
. eq ( "aPtitleref" , APname )
. find ()
. then (( results ) => {
if ( results . items . length > 0 ) {
let partitem2 = results . items [ 0 ];
let complete = partitem2 . complete ;
if ( complete === true ) {
$item ( “#button9” ). label = “Complete” ;
$item ( “#checkbox2” ). checked = true ;
$item ( “#button9” ). style . backgroundColor = “#FFFFFF” ;
$item ( “#button9” ). style . borderColor = “#550E9B” ;
$item ( “#button9” ). style . color = “#550E9B”
}
}
} )
} )
})
})
})
$w ( “#dataset2” ). onReady (() => {
$w ( “#repeater1” ). onItemReady (( $item , itemData , index ) => {
let aptitle = itemData . title ;
let webpage = aptitle . trim (). replace ( /\s+/ g , ‘-’ ). toLowerCase ();
$item ( “#button9” ). onClick (() => {
wixLocation . to ( “/fillable-forms-1/” + webpage );
console . log ( “/fillable-forms-1/” + webpage )
})
})
})
});
Some comments on your code…
-
It is incorrect to have more than one dataset.onReady(). I really don’t know which one is the one that executes.
-
The Repeater.onItemReady() should be outside of the dataset.onReady().
-
You also have one Repeater.onItemReady() inside each dataset.onReady(). I also have no clue which one will actually run.
-
You should only have one Repeater.onItemReady() function, which runs when the Repeater is being populated.
You say that the “Live site was working fine on Friday.” I’m honestly not sure how. But let me ask, what was it doing ? Or better, what are you trying to accomplish ?
Thank-you for your honesty and for the corrections. I have tidied it up. Still the error 500 pages occur, not very time a button is clicked, but sometimes.
import wixUsers from 'wix-users';
import wixData from 'wix-data';
import wixLocation from 'wix-location';
$w.onReady(function () {
// Write your JavaScript here
$w("#repeater1").onItemReady(($item, itemData, index) => {
$w("#dataset2").onReady(() => {
// ...
let aptitle = itemData.title;
let user = wixUsers.currentUser;
let userId = user.id; // "r5cme-6fem-485j-djre-4844c49"
let isLoggedIn = user.loggedIn; // true
let userRole = user.role; // "Member"
user.getEmail()
.then((email) => {
let userEmail = email; // "user@something.com"
console.log(userEmail);
console.log(userId);
wixData.query("participantworksheets")
.eq("title", userEmail)
.eq("aPtitleref", aptitle)
.find()
.then((results) => {
if (results.length == 0) {
let toSave = {
"title": userEmail,
"aPtitleref": aptitle,
};
wixData.save("participantworksheets", toSave)
.catch( (err) => {
let errorMsg = err;
} );
}
})
$w("#repeater1").forEachItem( ($item, itemData, index) => {
let APname = $item("#text13").text;
wixData.query("participantworksheets")
.eq("title", userEmail)
.eq("aPtitleref", APname)
.find()
.then((results) => {
if (results.items.length > 0) {
let partitem = results.items[0];
let begun = partitem.begun;
let complete = partitem.complete;
if (begun === true) {
$item("#button9").label = "Continue Writing";
$item("#checkbox1").checked = true;
}
if (complete === true) {
$item("#button9").label = "Complete";
$item("#checkbox2").checked = true;
$item("#button9").style.backgroundColor = "#FFFFFF";
$item("#button9").style.borderColor = "#550E9B";
$item("#button9").style.color = "#550E9B"
}
}
} )
} )
let webpage = aptitle.trim().replace(/\s+/g, '-').toLowerCase();
$item("#button9").onClick(() => {
wixLocation.to("/fillable-forms-1/" + webpage);
console.log("/fillable-forms-1/" + webpage)
})
})
})
})
});
Before I tackle your code (and yes, there still are issues), what is it you are trying to do ? It’s difficult to know what’s wrong, or right, with the code, without knowing what it is you’re trying to accomplish.
Okay, sorry. Items in the repeater represent different worksheets or tasks for participants stored in a database (“FillableForms”). The first time a participant makes contact, the webpage prepares the “participantworksheets” database for their entries. Participants choose a task to work on by clicking button9 in the repeater. This takes them to the specific worksheet. They begin to work and save their data into the participantsworksheets database (begun === true, checkbox1 is checked.) When they return they see that it is checked, and furthermore the label on the button says “Continue Writing”, ie. continue your work (a visual to show their progress). Whenever the participant finally finishes and reviews/submits their work (complete === true, checkbox 2 is checked) button9 says “Complete” and appears as a different colour (a visual that they do not have to continue work on this task.)
Your Repeater appears to be trying to do too much. To be honest, I’m not really sure what it’s doing.
The Repeater should be solely focused on listing the worksheets. When a participant clicks on a button for the worksheet to fill out, they are then taken to a new page with that worksheet. When the visitor’s worksheet is submitted (saved) on the worksheet page, they can then be redirected back to the page with the list (Repeater) of worksheets.
Here’s one example of a Repeater page that takes the visitor to a “details” page when clicking a button of a Repeater item.
Okay, thanks for your help. Our website has been running properly again since early Monday morning. We need the customization our repeaters offer. However, it it should fail again, perhaps we will have to look at using a more vanilla repeater as you suggest.