I haven't worked with comboBoxes, but have you tried looking at comboBox.choiceList, as in setting the choice to comboBox.choiceList; or something similar?
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;
So far I haven't been able to find such a property.
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 = "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.
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).
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.
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.
The only way I've been able to make it work is to click the first item in the panel, under PDF options:
Once I do this and publish to interactive PDF, the combobox displays the item by default:
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.
The script I'm using is as follows:
var cBox = app.selection.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;
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.
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.