Collapse/Expand elements in a dynamic page if a field in a database is empty

Hey everybody!

Well my question is just the title: How can I collapse a text if that field is empty in the database?

For example: I’m trying to put 3 languages. If the second and third are not filled I want that the dynamic page with their information (like a profile) just shows 1 language without having a big space under that (because the second and third languages are there empty).


(I tried a query, to getCurrentItem and something else but I couldnt manage to do it)

Hi Blai,

You were too close to solve it, you only need to check the status of that field :

if(!$w("#dynamicDataset").getCurrentItem().fieldName){ // i used (!) to check if its empty

For more information about getting the current item - Check this

Good Luck.


Hi Mustafa,

thanks for answering! It’s not working neither :frowning:

Be sure to change the ID’s for the elements and the dataset also.

has anyone out there figured out code that works for hiding an element on dynamic pages if the field/table cell is empty? no one seems to have an example of working code. Just code examples that moderators tweek and still don’t seem to work for the person looking for the answer.

Hello To anyone and ALL Moderators @mhammouz @ziv-shalev everyone seems “close”, what i’ve seen on reading and searching for an answer is it either hides all elements on every dynamic page or shows it on every dynamic page. With the end goal of hiding/collapsing and element when the field is empty

1 Like

@marketing-1 ,
Not working ? can you please show screenshot or paste your code!

@mhammouz Hello I would appreciate your help! I reached out to Wix support when i couldn’t get any code to work and they just refer me back here.

i need to hide a button when there is no url connected to it (in the field cell) and it isn’t working for me, i’ve tried using 2 different data sets thinking that was it too but to no avail.

$w.onReady( function () {
$w(‘#dynamicDataset’).onReady( () => {
let url= $w(‘#dynamicDataset’).getCurrentItem().cafeonline;
console.log(“url=” + url);
if (url) {
console.log(“inside if = true”);
} else {

i’ve tried this too and it didn’t work

$w.onReady( function () {
$w(“#dynamicDataset”).onReady(() => {
const item = $w(“#dynamicDataset”).getCurrentItem();
if (item[“url”] === undefined) $w(“#button51”).hide();
else $w(“#button51”).show();

Hi there, has this issue been resolved? I’m trying to find code for something similar.

Hi there, I am using this code and it seems to work perfectly, might anyone want to give it ago. Hope this helps.

$w(“#yourDataset”).onReady( () => {
let item = $w(“#yourDataset”).getCurrentItem();
if (item[“cafeonline”] === undefined) {
$w(“#button51”).collapse();//set height to 0
} else {
$w(“#button51”).show() ;
} );

Hi - anyone have any idea how to do this with text? i.e. collapse text/rich text fields when there is no content?

$w("#dynamicDataset").onReady( () => { let item = $w("#dynamicDataset ").getCurrentItem();
if (!item.text)("#text153") === undefined 
{ $w("#text153").hide(); $w("#text153").collapse();//set height to 0 } 
else { $w("#text153").show() ; }
} );

I’m sure there is bunch wrong there, but would appreciate the help. There are a bunch of text elements here, so would also like to know how to write this code to check multiple text elements. Thanks!

Hey Mustafa, can you give me some advice? Im trying to do similar thing, colapse a continer box if the “rich text field” on my dtabase is empty. I researched a lot, but no matter what code I use, problem is it is collapsing the Container Box no matter if the field it is empty or not. It’s being a pain :frowning:

Tryed this codes :

Collection name: EspecialidadesColection
Dataset name: LBset
Dataset Rich Text field key: altDesc1
Container box to collapse: box000002

//version 1:

$w.onReady(() => {
    $w("#LBset").onReady(() => {   

 const item = $w("#LBset").getCurrentItem();   // Checks if the current item has a value in the "altDesc1" field
 if (!item.altDesc1) {   // Collapses the image space if there is no value for "altDesc1"
          } else {

and this

//version 2:

$w.onReady(() => {
    $w("#LBset").onReady(() => {   

Both with the same effect, collapses everytime

So i have multiple music albums in my dataset, some albums have 9 tracks, and some 21 tracks, here is what I did and it is working great:

$w.onReady(() => {
$w(“#dynamicDataset”).onReady(() => {
let item = $w(“#dynamicDataset”).getCurrentItem();
if (!item.track10Name) {

Please be aware that this does not work with a repeater as far as I know.

#dynamicDataset - is the data access on my title page generated by the content manager
track10Name in the if statement after the !item. is the text field key in the date base
#audioPlayer10 is the audio player name on the title page

So basically, what this code does, any player on the title page that has a blank track name on the content collection database collapses.

The reason I wanted it to collapse is to make the players disappear and also the Strip pull up.

The reason I have ordered to collapse all the other players after it is because one of the albums has 21 tracks. (So basically when you create new content table, you need to create columns based on the maximum number of tracks your albums have in a database)

The reason I just stated in the if statement track10Name alone is that by logic any album that doesn’t have track 10 will not have another tracks after it.

Hope this helps.

For a repeater this code would work properly

#dataset1 - dataset
#teamRepeater - repeater
photo - field key of the database
#container1 - container in the repeater

$w . onReady ( function () {
$w ( ‘#dataset1’ ). onReady (() => {

$w ( '#teamRepeater' ). forEachItem (( $item, itemData, index )  =>  { 

if ( !itemData . photo ) {
$item ( ‘#container1’ ). collapse ();
} else {
$item ( ‘#container1’ ). expand ();

1 Like

This post is old and will be closed.

Please adhere to the Community Guidelines .