query with .isEmpty and collapse

I am trying to use isEmpty function to perform a query, if you visit this link below, under customise your home there are three buttons.
All i want is when i do the query if cell is empty first button is marked Ensuite option 1 collapses but if cell is not empty i shoud stay visible or expanded
if cell is empty for second one, 2nd button shoud collpase and so on

 wixData.query("HomeDesigns")       
 .isEmpty('ensuite1') 
 $W("Ensuite1").collapse (); 

HomeDesigns is my collection and ensuite1 is the coloum name and button is #Ensuite1
https://ravinderjassar.wixsite.com/malwahomes/HomeDesigns/Bartley-28-
can anyone help please
thanks
Ravinder

Hello

the following code is to get the isEmpty() result:

  wixData.query("HomeDesigns")
     .isEmpty('ensuite1')
     .find()
     .then( (results)=> {
     // here result will be all the items that have ensuite1 to be null or undefined
    });

However, is you want to know if the field is empty for the specific page then you should use .eq():

    wixData.query("HomeDesigns")
     .eq('title',$w('#dynamicDataset').getCurrentItem().title)
     .isEmpty('ensuite1')
     .find()
     .then( (results)=> {
        //if it is empty results.items.length >0
        //if not empty results.items.length =0 
        //in this if you see if there is empty 'ensuite1' for this page
         if (results.items.length) {
             $w('#Ensuite1').collapse();
         }
    });

Hope this helps!

Best
Massa

Thank you very much worked wonderfully, I really appreciate your help.

Could you please also tell me how to do a toggle button at the moment i am using click and double click event to switch and then switch back

thank you

Ravinder

Hello Ravinder

I’m glad it worked!

For the toggle, you mean like a switch ?
If so, you can add a switch button from the user input elements:

Best!
Massa

no its more like if i click on a button it shows an image and then when i click it again it reverts back to original image

this i what i am using now

export function CustomiseHome_click (event) {
$w(‘#Customise’).expand()

//Add your code for this event here:
}

export function CustomiseHome_dblClick (event) {
$w(‘#Customise’).collapse()
//Add your code for this event here:
}

Hello Ravinder

you can achieve that by doing the following check :

export function CustomiseHome_click (event) {
    $w('#Customise').collapsed ?  $w('#Customise').expand() : $w('#Customise').collapse()
}

this way if it was collapsed it gets expanded on click and if it was expanded it gets collapsed

Best
Massa

wonderful,

Thank you

Hi Massa

One last thing, I hope I am not annoying. this is working as it is but how do I do it off single function same as what we did collapse and expand check

I dont know if this is the right way of doing this but it seems to be working, its loading photos

Thank you in advance

export function MirrorPlan_click (event) {
$w(‘#Orignal’).hide();
$w(‘#OrignalMirror’).show()
$w(‘#Ensuite11’).hide()
$w(‘#Ensuite22’).hide()
$w(‘#Extrabed1’).hide()
$w(‘#Alfresco’).hide()
$w(‘#Powder1’).hide()
$w(‘#Theatre’).hide()
$w(‘#UPlan’).hide()
$w(‘#UpPlanMirror’).show()

}

export function MirrorPlan_dblClick (event) {
$w(‘#Orignal’).show();
$w(‘#OrignalMirror’).hide()
$w(‘#Ensuite11’).hide()
$w(‘#Ensuite22’).hide()
$w(‘Extrabed1’).hide()
$w(‘#Alfresco’).hide()
$w(‘#Powder1’).hide()
$w(‘#Theatre’).hide()
$w(‘#UPlan’).show()
$w(‘#UpPlanMirror’).hide()

}

Hey

You can use the same way using .hidden instead of collapsed for each on of the items. - check this

Best
Massa

Hi Massa Salah! My post is quite similar. Could you maybe help me with my questions by the link below:

https://www.wix-forum-community.com/forum/forum-discussions/if-database-field-is-filled-show-else-not

Thank you!