Highlighted

Script to set combobox default choice in InDesign CC 2018

Explorer ,
Jul 17, 2020

Copy link to clipboard

Copied

Hello,
I'm using a script to add combo boxes in InDesign CC 2018, but have no idea how to set the first item on the list as the default choice.  I can set the default choice manually in the Buttons and Forms panel by clicking the first item on the list, but would like the script to handle this selection automatically.
Buttons and Forms Pane.png
Looking at the InDesign Object Reference, the combobox class includes a comprehensive list of properties, however, setting a default choice doesn't seem to be one of them. 
Is this selection possible through scripting?
Thanks

Thanks to @brianp311 for his feedback.  I think we arrived to the conclusion that setting the default choice for comboboxes through scripting is not currently possible in InDesign.  I will have to continue doing this task manually.

Topics

Scripting

Views

133

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

Script to set combobox default choice in InDesign CC 2018

Explorer ,
Jul 17, 2020

Copy link to clipboard

Copied

Hello,
I'm using a script to add combo boxes in InDesign CC 2018, but have no idea how to set the first item on the list as the default choice.  I can set the default choice manually in the Buttons and Forms panel by clicking the first item on the list, but would like the script to handle this selection automatically.
Buttons and Forms Pane.png
Looking at the InDesign Object Reference, the combobox class includes a comprehensive list of properties, however, setting a default choice doesn't seem to be one of them. 
Is this selection possible through scripting?
Thanks

Thanks to @brianp311 for his feedback.  I think we arrived to the conclusion that setting the default choice for comboboxes through scripting is not currently possible in InDesign.  I will have to continue doing this task manually.

Topics

Scripting

Views

134

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
Adobe Community Professional ,
Jul 17, 2020

Copy link to clipboard

Copied

I haven't worked with comboBoxes, but have you tried looking at comboBox.choiceList, as in setting the choice to comboBox.choiceList[0]; or something similar?

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
Reply
Loading...
Explorer ,
Jul 18, 2020

Copy link to clipboard

Copied

Hello Brian,

I wish the combobox class would include a property that would accept the choiceList index you mentioned.  Something like "defaultChoice" below:

 

comboBox.defaultChoice = comboBox.choiceList[0];

 

So far I haven't been able to find such a property.

Thanks

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
Reply
Loading...
Adobe Community Professional ,
Jul 19, 2020

Copy link to clipboard

Copied

By default, the first item in the ComboBox Choice List in the interactive PDF will be selected when the user opens the IPDF. If you wanted to rearrange what the default is through the script, you could set comboBox.choiceList[0] = "XXX"; or add a new entry at the beginning by using unshift: comboBox.choiceList.unshift("New default string");

You could also roll a custom sort option for the choiceList array.

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
Reply
Loading...
Explorer ,
Jul 19, 2020

Copy link to clipboard

Copied

Hmmm... once the choiceList array for the combobox is created,

cBox.choiceList = ['Choice 1', 'Choice 2', 'Choice 3', 'Choice 4'];

I'm not able to modify the array elements, either by using unshift(), or any other methods like push(), pop(), etc.  The only way I can do this is by declaring a new array and adding new elements.

The other thing I've noticed is that the combobox in the published interactive PDF does not default to any of the choices (it's completely blank).

Combobox Test.png

The only way I've found to set the default choice is to manually click an option in the Buttons and Forms panel.

Could it be possible that we're discussing two different versions of InDesign here?  Like I said earlier, I'm using InDesign CC 2018.

 

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
Reply
Loading...
Adobe Community Professional ,
Jul 19, 2020

Copy link to clipboard

Copied

I don't think it's a versioning issue. You're right on not being able to manipulate the array as I thought. I was able to set the default only after selecting the item in the list. What option are you clicking in the panel to set it? Or are you just clicking on the item? 

After poking around some more, I think you're probably out of luck, or would need to script something in Acrobat. Sorry if I got your hopes up. 

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
Reply
Loading...
Explorer ,
Jul 20, 2020

Copy link to clipboard

Copied

The only way I've been able to make it work is to click the first item in the panel, under PDF options:

PDF Options.png

Once I do this and publish to interactive PDF, the combobox displays the item by default:

Set default choice.png

I've also been poking around, looking into the list of menu actions, and hoping to find an action that could be invoked from the Buttons panel, but alas, there is nothing there either.

No worries about getting my hopes up.  When I couldn't find a "default choice" property in the Object Reference, I figured my chances were probably slim to none.

I appreciate 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
Reply
Loading...
Engaged ,
Jul 17, 2020

Copy link to clipboard

Copied

Hello Nelway

 

Can you post your script for us to look at?

Regards

Mike

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
Reply
Loading...
Explorer ,
Jul 18, 2020

Copy link to clipboard

Copied

Hello Mike,

The script I'm using is as follows:

var cBox = app.selection[0].comboboxes.add();
cBox.geometricBounds = [0, 0, 0.25, 2];
cBox.choiceList = ['Choice 1', 'Choice 2', 'Choice 3', 'Choice 4'];

I'm unable to find a property (for instance, "defaultChoice") that could be used for selecting the first choice as default.  For example:

cBox.defaultChoice = cBox.choiceList[0];

Thanks

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
Reply
Loading...
Adobe Employee ,
Jul 25, 2020

Copy link to clipboard

Copied

Hi there,

 

Thanks for reaching out. I hope your issue is resolved now. We'd appreciate if you can mark the appropriate answer correct.

If you used any other method, please share it here. It'll help other users having similar concern.

If you still have issues, let us know. We'll be happy to help.

 

Regards,

Ashutosh

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
Reply
Loading...
Explorer ,
Jul 25, 2020

Copy link to clipboard

Copied

Thanks to @brianp311 for his feedback.  I think we arrived to the conclusion that setting the default choice for comboboxes through scripting is not currently possible in InDesign.  I will have to continue doing this task manually.

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