• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

Query re check box groups, help required please...

Participant ,
Aug 01, 2022 Aug 01, 2022

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.

TOPICS
Acrobat SDK and JavaScript , Mac

Views

72

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 01, 2022 Aug 01, 2022

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);

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 01, 2022 Aug 01, 2022

Copy link to clipboard

Copied

Hi Gilad,

Thanks for the help, much appreciated 👍

Thanks also for the PS coding tip 🙂

Cheers!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 01, 2022 Aug 01, 2022

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 01, 2022 Aug 01, 2022

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 01, 2022 Aug 01, 2022

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 01, 2022 Aug 01, 2022

Copy link to clipboard

Copied

I was thinking something like this.getField("xyz").checkThisBox([0-3],true);

so adding the [0-3].

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 01, 2022 Aug 01, 2022

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...

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 01, 2022 Aug 01, 2022

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 01, 2022 Aug 01, 2022

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 01, 2022 Aug 01, 2022

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?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 01, 2022 Aug 01, 2022

Copy link to clipboard

Copied

Sure. In that case you can use this code:

this.getField("xyz").value = "Off";

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 02, 2022 Aug 02, 2022

Copy link to clipboard

Copied

LATEST

Great, thanks again Gilad 👍

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines