Hi,
premise: I’m not a programming expert so I apologize if my language or declarations may seem incorrect.
I have a page (for test) containing a repeater connected to a database.
A couple of fields (a ‘text’ and a ‘gallery media’) may be empty in some records.
My goal is to compress the space in the repeater when one or more fields in the database are empty.
The database has the following structure:
The name of the database is ‘DB_Comune’ while the ID (as displayed in the page is ‘dataset1’)
And this is the code taken from an example and modified:
The code does not work and all the photo galleries (even if present in the record) are not displayed.
Can anyone tell me where I’m wrong? I’ll be grateful for the help and assistance you will give me - thanks
The code would probably work if you were not using a repeater to do this in, like in the original example for if the video field is empty.
https://support.wix.com/en/article/corvid-tutorial-hiding-a-video-player-when-there-is-no-video-to-play
However, when you use a repeater you need to code it differently and for each container item itself, otherwise it will be applied to all repeater containers as you have got it.
https://www.wix.com/corvid/reference/$w.Repeater.html
If you searched before posting, you might have found your answer already…
https://www.wix.com/corvid/forum/community-discussion/collapse-empty-elements-in-a-repeater
Hi GOS, thank you very much for your reply. I will definitely follow your advice and keep you informed of the result.
Actually, before inserting my post, I searched the forum but evidently I missed the topic or I did not set the search correctly.
I apologize, thanks again and good evening
Hi GOS,
the problem has been solved but, compared to the proposed example (which still created difficulties), with a modification to the code and to the database.
A text field has been added to the database in which to insert a value in case of absence of images while in the code the control is performed on the new field instead of the ‘gallery media’ field:
This because the previous code does not seem to detect the NULL value.
Any ideas on this?
In any case, thanks again and good evening.
Did you include the ‘!’ straight after the if on line 3 in your original testing with the linked forum post and with the linked tutorial as well?
The exclamation mark is in there for a reason and you can read about this on many other online pages…
https://stackoverflow.com/questions/8012003/what-is-an-exclamation-point-in-javascript
https://www.tutorialspoint.com/What-does-the-exclamation-mark-do-before-the-function-in-JavaScript
https://medium.com/better-programming/javascript-bang-bang-i-shot-you-down-use-of-double-bangs-in-javascript-7c9d94446054
Code from linked forum post
$w("#myRepeater").onItemReady( ($w, itemData, index) => {
if (! itemData.document) { // based on your "empty status" you need to change this line.
$w("#rankingsBtn").disable();
}
});
Code from linked tutorial
$w.onReady(() => {
$w("#myDataset").onReady(() => {
// Gets the current item properties and stores them in a variable called item
const item = $w("#myDataset").getCurrentItem();
// Checks if the current item has a value in the "video" field
if (!item.video) {
// Collapses the video player if there is no value for "video"
$w("#videoPlayer").collapse();
}
});
});
Line 6 checks to see if the item variable from the previous line includes the video field, which is the field in the collection that stores the video URL.
if (!item.video) {
If the current item’s video field is empty, then that field is not included in the object that was returned by getCurrentItem in the previous line.
So what part of the code here didn’t work for you?
$w.onReady(() => {
$w("#repeater1").onItemReady( ($w, itemData, index) => {
if (! itemData.immagini) {
$w("#gallery1").collapse();
}
});
});
Anyways, if you want to just do a simple if statement instead as that works for you, then do it like as shown in these previous posts here and you shouldn’t need to use the additional text field either.
https://www.wix.com/corvid/forum/community-discussion/solved-collapse-only-empty-text-fields-for-repeater-items
https://www.wix.com/corvid/forum/community-discussion/if-else-collapse-for-repeater-items
Also, just to mention for you to check how your repeater is setup with your gallery element inside of it and see if it is being affected when the gallery is supposed to be collapsed.
https://support.wix.com/en/article/corvid-how-page-layout-is-affected-when-elements-change-size
@givemeawhisky Hi, the reply to your first question (i.e.: Did you include the ‘!’ straight after the if on line 3?) is: ‘yes, I do’
I reset the code as per your example:
and this is the relevant preview:
the dark box of the first repeater should not appear - I don’t know where is the error but the null field doesn’t seem to be detected
I have the same issue, the solutions shared here does not seem to work on Wix Galleries inside repeaters. Wish the ninjas and the gurus can come in and end our misery.
This has got to be one of the frustrating forums to go on for answers. As I do not know of any other, I’d have to endure and be patient. Again, how is it that after a year, no one has posted an explanation as to why the codes recommended on this thread work for everything else except for galleries? Empty/undefined/null galleries don’t seem to get detected properly/consistently.