Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

Clear Dropdown list selection

Avatar

Former Community Member
Hi, I've been trying to figure out a way to clear the chosen selection in a dropdown list, without removing all of the variables in the list. I've used the script provided in the forums which allows a user to select a variable in a dropdown list, which is then added to a textbox. But after that is done I want the dropdown list to "reset" itself to a blank value. Can anyone assist a humble newbie?



//Anders
9 Replies

Avatar

Former Community Member
You can say



DropDownList1.rawValue = null;



This will clear the value out of it.

--

SteveX

Adobe Systems

Avatar

Former Community Member
Thanks, it worked nicely under "exit"...



It would also be nice to have a script that says that a varible can only be added to a list once. Do you have anything on that??



Anders

Avatar

Former Community Member
The implementation of such a solution (where an item/variable is only added to a list once) can be done either at the point where you're adding items to the list or after you've added items to the list.



If you do it "at the source" (while you're populating the list), then you could use a series of arrays to "remember" the items you've already added to the list and, for every subsequent item (after the first item), check those arrays to verify that it doesn't match any items you've already added. It must be done this way because the list object's items don't actually get updated in the Object Model until after the event in which you're adding the items terminates. I know, it doesn't make sense, but that's the reality of it.



If you do it after the items have been added, it's a little easier. In this case, you could write script in the drop down list's PreOpen event (this is fired as the user clicks on the drop down button just before the list is shown). In this script, you would look at the items in the list and, for every item, search all subsequent items for instances of the "search item" and remove them.



The problem with list objects is that the XFA Scripting Model doesn't offer any convenient way to get the number of items they contain and then get information on a particular item (like what its text and value are) so we're forced to go into the AcroForm Acrobat Object Model object which wraps the XFA object because that model offers the information we're looking for. It also provides the ability to remove a specific item from the list while XFA doesn't.



I've attached a sample form which implements the latter solution (check on PreOpen for duplicate items). It uses a Script Object variable to determine whether the check should be done (you don't want to do this check on every drop down because it's a potentially expensive check to do and there's no need to do it more than once anyway). It also uses the list object's AcroForm wrapper to perform the operations needed on the list. Note that the sample assumes that the drop down list has already been populated by some method.



Let me know if you have any questions.



Stefan

Adobe Systems

Avatar

Former Community Member
Hi Stefan, thanks for all your help.



I was just thinking about text fields. Do you know if there is a way to put the values in a dropdown list to a second text field, if the first one gets full? Is it possible to add a string to the script that tells the dropdown list to continue adding variables to a second text field, linking the text fields together?



/Anders

Avatar

Former Community Member
I think you meant to ask if there was a way to have items spill over to a second drop down list (not text field) when the first one gets full.



There's always a way to do things but there's no real "maximum" number of items you can put into a drop down list. There's a practical limit (afterwhich the drop down list becomes basically unusable because there are too many items to scroll through) but the only physical limit should be memory.



You could certainly setup your form with two lists and add a condition in the code which checks for the number of items in the first list. Once a certain maximum number of items is reached, you would simply stop adding items to the first list and continue adding them to the second.



I can't say that this sounds very practical/usable for someone filling-in your form (to have two separate drop down lists containing a single list of information). If you could logically split the information into two groups (like categories and then the items they contain), I think it would make more sense.



Stefan

Adobe Systems

Avatar

Former Community Member
Oh no, you misunderstood me, my mistake :-)



I really wanted to add the items in the dropdown menu to two separate text fields. When the first text field becomes full, I want the second one to start recieving the items from the dropdown menu, just like two columns.



/Anders

Avatar

Former Community Member
I see. So you want to transfer the items in a drop down list into two text fields which represent two columns. Hopefully I've got it this time.



Since there's still no "maximum" length on a text field (unless you set one), you would have to either have a hard-coded limit for the number of items in one column or calculate the limit according to the data (maybe you always split the data in half so half the items go in one column and the other half goes in the second one).



Essentially, you simply need to iterate through the items in the drop down list in the same fashion as my previous sample did and then add each item, followed by a new line character, to multi-line text fields. As you're transferring the items, check to see if you've hit the maximum count for a column and switch over to the second one.



I've attached another sample which transfers the items from a drop down list into two text fields. The number of items that go into the first one is determined by the count specified in the numeric field next to the "fill columns" button which you click to transfer the items over. As for the two column text fields, I set them up as multi-lined with a growable height so that they always grow to fit all the items so that they're all in view but you could always set a specific height and require the user to scroll through their content. You can also change the "split at" value and transfer the items again and again if you like.



Stefan

Adobe Systems

Avatar

Former Community Member
Ok, sounds good. But if I, for instance, would want to add 7 rows to the first column and then automatically continue to the second column, how would I type the script? Can I put among the dropdown list scripts, avoiding a button?



/Anders

Avatar

Former Community Member
It depends on what event will trigger the transfer of the items from the drop down list to the two column text fields. Whatever event that is, it must be after the drop down list is populated and it's in this event (the trigger) that you would place the script I put in the button's Click event. The script would then have to be modified to get this number (your number 7) from somewhere. If it's always going to be 7, then you would just need to replace



var nSplitAt = new Number(SplitAt.rawValue);


with



var nSplitAt = 7;


and the rest of the script should work as expected.



Stefan

Adobe Systems