Boolean display

Hi guys,

What is the best way to display a boolean? I have 50 or so amenities with boolean fields and was hoping to display with checkboxes but I guess they are only for input?

My work around is this:

$w.onReady(() => {
$w(“#dynamicDataset”).onReady(() => {
let items = $w(“#dynamicDataset”).getCurrentItem().airConditioning;
if (items === true) {
$w(“#checkbox1”).checked = true;
}
});
});

But I don’t want to have to do this 50 times. Is there a better way?

Hi Splatty,

Rename the check boxes to checkbox0, checkbox1, checkbox2 etc and use a loop to iterate the boolean collection fields, each time either checking the box or doing nothing.

Thanks Ido that sounds great. I haven’t tried this before would you mind giving an example?

Splatty, here’s a general example (with a fixed number of checkboxes):

const numberOfCheckBoxes = 17;
for (let i = 1; i <= numberOfCheckBoxes; i++) {
    $w(`checkbox${i}`).checked = true;
}

Liran

Thank you Liran. How does it reference the separate boolean fields from my databse though?

You’ll need to read all fields from database and set their value accordingly.
This depends on their name in database, or order.

I’m sorry can you layout the format for me with the reference and the loop so I can see how to do it? Thank you.

Just a thought… it’s a dynamic page, why didn’t you just connect the checkboxes to the dataset?

Anyway, for code:
Lets say you have 3 columns in database:
airConditioner, childFriendly, airPort.

And let’s call the checkboxes ‘airConditionerCheckBox, childFriendlyCheckBox, airPortCheckBox’ accordingly.

$w.onReady(() => {
	$w("#dynamicDataset").onReady(() => {
		let currentItem = $w("#dynamicDataset").getCurrentItem();
		for (let key in item) {
			if (item[key] === true) {
				$w(`${item}checkBox`).checked = true;
			}
		}
	});
});

Liran.

Awesome. I wanted to just connect to the dataset but it wouldn’t work? I assumed as it is an input?? So it can be done that way?

It should be.
Don’t assume things are not possible, try them :slight_smile: trying is free of charge.

Liran.

nope doesn’t work when I connect them to the dataset?

Probably some configuration issue.
If code works for you - go with it.

Somewhat related question…setting up a dynamic page with amenities/services and trying to establish best fields/user input for form so on the dynamic page, only those selected show by name. But the issue is making them appear only if selected. Therein is the problem as do not want spaces if not selected
Example:

Breakfast
Lunch
Dinner

If set up user input form and say, they only have Breakfast…that is not hard, as shows up first in list. But let’s say they only choose Dinner…then if using text fields on dynamic page to show, then there are two blank spaces…if you have a lot of options, that creates a lot of blank space. What am I missing in constructing (I am codeless)

Hi !

I wish to display a text element according to whether a boolean is checked or not in the collection.

Here is the code I tried, but it doesn’t work :

$w("#dynamicDataset").onReady(() => {
 let items = $w("#dynamicDataset").getCurrentItem().dispo;
  if (items === true) {
            $w("#text113").show;
        } 
});

the boolean field is named “dispo”

Thanks !

Hi Tristan,
Can you please post your question on a new thread? Moreover, please clarify what you would like to achieve.

Thanks,
Tal.

Hy Liran,what program will you create with boolean?

I’m newbie in programming…somebody please teach me :slight_smile:

How can the SWITCH INPUT possibly used in this scenario?