I tried my hardest, I really did (lol) but, I cannot for the life of me figure out how to do this . Hopefully I can explain what this is, well enough.
So I have my repeater, and in my repeater there are Subtitles that are connected to a collection. For the items in my Dataset, they don’t alway have a Subtitle, so while the placeholder text is not visible if there is no Subtitle in the dataset, there is a blank space where it would be.
What I’m trying to do, is “If Subtitle is Empty, Collapse Text”, so that blank space is no longer visible when there is no Subtitle for an item.
Here’s some what I’ve tried so far.
Method 1
$w.onReady( function () {
$w("#repeater1").forEachItem( ($w) => {
let hasSubtitle = $w("#subTitle");
let searchValue = $w("#subTitle").text;
wixData.query('Video-Library')
.eq("subtitle", searchValue)
.find()
.then( (results) => {
let blankSub = results.items;
if (blankSub) {
hasSubtitle.collapse();
}
else {
hasSubtitle.expand();
}
});
});
});
I can’t remember what else I’ve tried but they were all along the same lines. Please help me figure this out! I hope I’m not too far off because I’ve been tinkering for hours.
Hi,
You should use the query function a bit differently:
let hasSubtitle = $w("#subTitle");
let searchValue = $w("#subTitle").text;
wixData.query('Video-Library')
.eq("subtitle", searchValue)
.find()
.then( (results) => {
//here you get all the DB records that their "subtitle"
//fields equals to searchValue
let videos = results.items;
//this is an array, therefore, should check for each record
videos.forEach((video) => {
//video doesn't have a sub title
if (video.subtitle === null) {
hasSubtitle.collapse();
}
};
});
});
Note that I used the if statement only in case there is no sub title for the video. Otherwise, it should display the element and therefore there’s no need to expand it (since it is expanded by default).
I hope it’s clear.
Should the issue persists, please send us the site URL and the [age you were referring so that we can have a look.
$w("#repeater1").onItemReady(($w, itemData, index) =>{
if (!itemData.subtitle) {
$w("#subTitle").collapse;
}
});
onItemReady function, called on repeater, adds function which executes each time when container gets data from dataset
I tried it on your site, but problem is that i didn’t see any subtitles there to check) on page which you mentioned
Only a few actually have subtitles,
Item 11 (Title: You’re Not A Virgin [lmao OMG so weird typing this in a public forum]) is the first item to have a subtitle. I’ve changed the limit to 30 items for now so it can be seen on the main page view.
$w("#repeater1").onItemReady(($w, itemData, index) =>{
if (!itemData.subtitle) {
$w("#subTitle").collapse();
}
});
No reason to put it somewhere into onReady for dataset. Just under main onReady() function. We’re setting here behavior for every container - when it’s ready, if subtitile is empty, this comp collapsed
This should work for any type of element, correct? If so, then I probably need a tad bit more explanation.
$w("#repeater1").onItemReady(($w, itemData, index) =>{
if (!itemData.approachPhoto1) {
$w("#image9").collapse();
}
});
approachPhoto1 is the header on the image field in the database, and image9 is the element on the page. As for “#repeater1” it’s not very clear to me what this is suppose to be. I’ve left it as is, and I’ve substituted suggestions after using ctrl+space and none of them have worked.
Hi! I’m not sure what you want to achieve. Please, describe your usecase more
onItemReady event handler is relevant only for repeater. This sets up a function, which will be executed when any container within repeater is ready and got it’s data. And those functions are disfferent - it’s one per one container
Ahhh, I seem to have misunderstood the repeater part of this. Anyway, I’m creating a website template for writing trip reports. The template might have spaces for say 10 images, but I might only use 8 of them. I’d like the dynamic page to automatically hide the other two images.
Hi! I’m doing a menu page where many menu items are shown on the page. The container where the description is shown is #text6 and the column name in the dataset is Description. I used the code shown above and it works… a little too well. Now, all the descriptions are collapsed, not only the ones with empty descriptions.
Here’s the code I have :
$w("#repeater1").onItemReady(($w, itemData, index) =>{
if (!itemData.Description) {
$w("#text6").collapse();
}
I’m not a programmer so I don’t understand a lot in the code. I guess my problem is I have nothing to tell the not empty ones not to collapse. I tried adding the else part, but it didn’t work.