Hi! Im trying to collapse sections of my dynamic page when the field database is empty. I had no problem with collapsing certain sections of the page, but when I added new elements/sections I am unable to collapse those new added sections despite using the same code. Please help!
Ive attached the code below:
$w.onReady(() => {
$w(“#dynamicDataset”).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.section {
// Collapses the video player if there is no value for “boolean”
$w(“#section7”).collapse();
if (!item.text {
// Collapses the video player if there is no value for “video”
$w(“#text23”).collapse();
if (!item.text {
// Collapses the video player if there is no value for “video”
$w(“#text24”).collapse();
if (!item.section {
// Collapses the video player if there is no value for “video”
$w(“#section8”).collapse();
if (!item.section {
// Collapses the video player if there is no value for “video”
$w(“#section2”).collapse();
if (!item.section {
// Collapses the video player if there is no value for “video”
$w(“#section5”).collapse();
if (!item.section {
// Collapses the video player if there is no value for “video”
$w(“#section6”).collapse();
for reference, Im unable to collapse section 7 and section 8 when I run it, but sections 2,5 and 6 work just fine!
A. please format the code using ```js at the start, and ``` at the end, like so:
// your code here
B. Your code has errors, either you didn’t copy/paste it properly, or it is simply broken and won’t compile. Please ensure the correct code is here, so we can try and assert what’s wrong
Like Dean already mentioned, your code is definetelly incomplete.
In future always try to give all needed details about your issue.
Only showing some totaly broken code, without a detailed description of at least providing some facts about your data/database and how you structured your setup exactly, it will become difficult to help you out.
If it would be me, i think i would do it something like…
$w.onReady(() => {
$w("#dynamicDataset").onReady(() => {
// Gets the current item properties and stores them in a variable called item
const item = $w("#myDataset").getCurrentItem();
// Array of field names to check and corresponding section IDs to collapse
const sectionsToCollapse = [
{ field: 'section', id: '#section7' },
{ field: 'text', id: '#text23' },
{ field: 'text', id: '#text24' },
{ field: 'section', id: '#section8' },
{ field: 'section', id: '#section2' },
{ field: 'section', id: '#section5' },
{ field: 'section', id: '#section6' }
];
// Loop through each section and collapse it if the associated field is not set
sectionsToCollapse.forEach(section => {
if (!item[section.field]) {
$w(section.id).collapse();
}
});
});
});
But unfortunatelly this is still not dynamic enough out of my view.
This needs to be improved much more.
The rest will be done by @Dean, i am to lazy today 
By the way! Why should you go the dynamic way?
Beacause doing so, you wouldn’t have broken your code now, because there wouldn’t be any need to change your code, after adding new setions.