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

Dynamically changing list Items for a series of Comboboxes after selection

New Here ,
Aug 07, 2024 Aug 07, 2024

I've been banging my head against this one for a while.

Premise: I have 72 Comboboxes on a PDF. When the PDF opens, they are empty (each has only a space " ") for value and List Items. When a selection is made elsewhere in the PDF, it populates the Comboboxes with default values pulled from a document-level array, then updates another document-level array with the new information, which is then sorted using a custom sort function and finally written to the comboboxes in a single function.

The problem: The comboboxes populate initially just fine. But when I go to make a selection and the array is resorted and tries to write to the comboboxes, I either get an error (if I try to update the .value of the field) or I end up with the wrong item selected in the 'active' Combobox because it seems to remember the index of the item I originally selected. Trying variations of .currentValueIndices doesn't much seem to help.

For example, when I enter a number elsewhere on the pdf, it creates two entries in my first two Comboboxes, both with the same list items (pulled from that first document-level array), let's say this is the array:

0 : "--select--"

1 : Apple

2 : Orange

3 : Pear

So far, so good.

What I want to happen is when I select 'Apple' in combobox1, a function updates the array to remove "--select--" from the nested array holding that data. Then it updates the array for combobox2, removing "Apple" from the nested array for the list, because you can't pick the same fruit twice. The array is then sorted (this is key to my problem!), which moves the array without 'Apple' into combobox1 and the array without '--select--' into combobox2. Then I have a function to write all of the data from the array to the two comboboxes.

If I try to update combobox1 in a keystroke custom script with this.getField("combobox1").value = "--select--", I get a "InvalidSetError: Set not possible, invalid or unknown" error. If I try to update combobox1 with "event.currentValueIndices = 0;" it still selects the index value of the original element that I clicked... so, in this example, if I select 'Apple' it changes the selection to 'Orange' because 'Orange' is now at Index 1, because 'Apple' is no longer in the list. Whatever I do, it just refuses to select '--select--' after sorting and processing the array.

The relevant code:

 

function writeTableData() {
	sorttableDataArray();
	var changedRowIndex = event.target.name.replace("combobox",'');
	changedRowIndex = Number(changedRowIndex) ? Number(changedRowIndex) : -1;
	/* this.resetForm([event.target.name]);*/
	for (var tableDataArrayIndex in tableDataArray) {
		/* when tableDataArray[tableDataArrayIndex][7] is set to 0, it tells this function that data has changed and we need to update the comboboxes */
		if(tableDataArray[tableDataArrayIndex][7] == 0) {
			/* the row number of the combobox is stored in tableDataArray[tableDataArrayIndex][0], so pull that out now so we know which combobox we're working with */
			var subAreaRowIndex = tableDataArray[tableDataArrayIndex][0];
			var subAreaComboBox = this.getField("combobox" + subAreaRowIndex);
			var originalSubAreaComboBoxRC = subAreaComboBox.rc;
			subAreaComboBox.rc = false;
			/* The list item array for the combobox is stored in tableDataArray[tableDataArrayIndex][3], so pull that into its own array and then use .setItems to update the combobox's list items */
			var subAreaComboBoxListArray = new Array();
			subAreaComboBoxListArray = tableDataArray[tableDataArrayIndex][3].slice(0);
			subAreaComboBox.setItems(subAreaComboBoxListArray);
			/* the new value of the combobox is stored at tableDataArray[tableDataArrayIndex][2] */
			var subAreaWriteValue = tableDataArray[tableDataArrayIndex][2];
			/* get the index of the value from subAreaComboBoxListArray by getting the .indexOf subAreaWriteValue */
			var subAreaWriteIndex = subAreaComboBoxListArray.indexOf(subAreaWriteValue);
			/* if this is a row we've made a new selection on, update event.currentValueIndices to the new index (this doesn't work) */
			if (subAreaRowIndex == changedRowIndex) {
				event.currentValueIndices = subAreaWriteIndex;
				/* event.value = subAreaWriteValue; - this is another option I've tried, it does nothing */
				/* subAreaComboBox.value = subAreaWriteValue; - this is another option I've tried, I get the InvalidSetError */
			} else {
				/* if this is a row we haven't made a selection on, we can just update the value with no problems */
				subAreaComboBox.value = subAreaWriteValue;
			};
			subAreaComboBox.rc = originalSubAreaComboBoxRC;
			/* once we've written to the comboboxes, reset tableDataArray[tableDataArrayIndex][7] to 1 to indicate that row is locked for editing */
			tableDataArray[tableDataArrayIndex][7] = 1;
		};
	};
}

 

I think, if I can figure out where Adobe is storing the index of the list item I selected, then I should be able to manipulate that index to the value I need it set to. But so far, no combination of .currentValueIndices seems to hold that data to manipulate.

Thoughts?

TOPICS
How to , JavaScript , PDF forms
379
Translate
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 08, 2024 Aug 08, 2024

In my experience, it is very tricky to do what you're trying to do. A much easier solution is to simply use a Validation script to reject a value that was previously selected in another field, instead of removing that item from the list entirely. I suggest you consider doing that, instead.

Translate
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
New Here ,
Aug 28, 2024 Aug 28, 2024
LATEST

Whelp, definitely not the answer I was hoping for, but I hear you. I suppose I'll have to add in a 'resort' button to achieve what I'm looking to do.

Translate
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