Hi,
I’m trying to hide a wix audio player that’s in a repeater if there is no audio file present in the dataset. For example, the ‘Real City Heros’ and ‘Iron Heart’ sections don’t have any audio files attached, but wix has put temporary music in its place. This is obviously no good, as the site is to display our music work.
I got this code from a wix guide and adjusted it to match my dataset and fields: https://support.wix.com/en/article/corvid-tutorial-hiding-a-video-player-when-there-is-no-video-to-play It doesn’t provide me with any errors but also doesn’t do anything.
$w.onReady(() => {
$w("#dynamicDataset").onReady(() => {
const item = $w("#dynamicDataset").getCurrentItem();
if (!item.audio) {
$w("#audioPlayer1").hide();
}
});
});
I’ve tried adding an else show command under $w(“
#audioPlayer1”).hide(); but that doesn’t help either. If i switch the hide/show commands around, then it will hide all the audio players.
I’ve also tried referring the code to a separate text field in case the wix temp music was causing the code to think there is an audio file there.
What am I missing?
There is also some code to filter the repeater on the same page, but I don’t think that is effecting it.
Yes that above code example will work fine if your Wix AudioPlayer was not in a repeater and just in the Wix AudioPlayer app, like the code example was originally with the video being just in the Wix VideoPlayer app.
As you are displaying your data in a repeater you will need to code your page for the repeater instead. Which you can simply find out how to do on previous forum posts like here,
https://www.wix.com/corvid/forum/community-discussion/collapse-empty-elements-in-a-repeater
https://www.wix.com/corvid/forum/community-discussion/if-else-collapse-for-repeater-items
For more info about working with repeaters etc, then pleaser read here.
https://www.wix.com/corvid/reference/$w.Repeater.html
https://www.wix.com/corvid/forum/corvid-tips-and-updates/example-input-repeaters
Thanks for your help. It was really useful. I managed to get it sorted straight away with the links.
I just changed:
$w("#dynamicDataset").onReady(() => {
to
$w("#repeater1").onItemReady( ($w, itemData, index) => {
This has worked, but now my audio player has got wider and I can’t resize it. This happens on all pages, even with new audio players. Do you have any idea why this might have happened? I haven’t changed anything else on the site apart from that one line of code.
Hey! Having a very similar issue however it’s still not working for me after giving it a try. Would really appreciate some help so I know where I’m going wrong:
https://www.wix.com/corvid/forum/community-discussion/hiding-audioplayer-if-database-field-is-empty
Hi Amir, In order to get help from the community, we need you to be more specific about your issue. Please create a new post with a detailed description, and include your code and any screenshots. Our posting guidelines are here. Thanks!