Copy link to clipboard
Copied
Hi there,
Just a quick question regarding checkbox groups.
I have a group of checkboxes and they're all named the same - xyz.
I can reference each checkbox as below:
var w = this.getField("xyz.0")
w.checkThisBox(0,true);
Using the index xyx.0, xyz.1, xyz.2 etc I can reference each checkbox individually.
Is there a way to get the number of checkboxes, or widgets, in the group?
I've tried a couple of things, such as w.length and w.count, but as yet haven't succeeded.
Obviously when trying to reference the group I'm using var w = this.getField("xyz"), there is no index as the code above.
Thanks in advance.
Copy link to clipboard
Copied
You can do it using the exportValues or page properties. Both will return an array, and the length of that array is the number of "widgets" in the group.
PS. The first parameter of checkThisBox is the index number of the box to check, so instead of doing it like this:
var w = this.getField("xyz.0")
w.checkThisBox(0,true);
You can just use:
this.getField("xyz").checkThisBox(0,true);
Copy link to clipboard
Copied
Hi Gilad,
Thanks for the help, much appreciated 👍
Thanks also for the PS coding tip 🙂
Cheers!
Copy link to clipboard
Copied
Just one small clarification, if there's only one widget the page property will return a number, not an array.
The exportValues property always returns an array, but it can only be used for check-boxes and radio-buttons, while page is available for any type of field.
Copy link to clipboard
Copied
Thanks for the clarification re the page propery.
Guess I'll need to catch that exception.
One other quick question, is it possible to affect all the checkboxes, in the group, in one go or do you have to loop through them all?
Thanks again.
Copy link to clipboard
Copied
"Affect them" in what way, exactly? Some properties apply at the field level, and others at the widget level.
If you change a field-level property it will affect all of them at once, yes.
Copy link to clipboard
Copied
I was thinking something like this.getField("xyz").checkThisBox([0-3],true);
so adding the [0-3].
Copy link to clipboard
Copied
That's not possible, and also doesn't make sense. You can't tick multiple boxes in the same group at the same time...
Copy link to clipboard
Copied
Yeah, though it didn't make sense. Just wondered if you could reference multiple objects like that.
Thanks again for the help.
Copy link to clipboard
Copied
No, the only way is to drop the ".X" part from the field-name, and then it accesses it at the field-level, or add it and then access a specific widget. You can't access a range of widgets directly.
Copy link to clipboard
Copied
Just a thought re this...
That's not possible, and also doesn't make sense. You can't tick multiple boxes in the same group at the same time...
You may want to untick a group in one go, is that possible?
Copy link to clipboard
Copied
Sure. In that case you can use this code:
this.getField("xyz").value = "Off";
Copy link to clipboard
Copied
Great, thanks again Gilad 👍