How to save a manually entered "custom text" in a dropdown to the list items for future choice?

Community Beginner ,
Jul 17, 2022 Jul 17, 2022

Copy link to clipboard

Copied

I have searched with no luck on this. In Access, you can add a manually entered text in a combo box to the associated table containing the list items. When the form is opened in the future, that list item that is newly created is now an available option.

Here is what I'm trying to do: My Location1,2,etc. dropdown boxes have one item below the blank space default item. When a user clicks and enters a location (the "Let users enter custom text" option is checked), after that option is displayed in the form, it is then saved to the list as a new list item. The next time the form is opened, there would be two locations listed, instead of just the one.

As an example, the box has Zoom Meeting only. The user attended a meeting at the mall. They type in "Mall" as the custom text. Next month, they have another meeting at the mall, but the form is blank because it is a new month. They click on the arrow in the dropdown, and "Mall" is now and available option to select.

I figure this is an easier and more efficient way than entering the same location month after month using "other" as an option and populating a text field or some other method of showing a location not in the list.

TOPICS
How to , JavaScript , PDF forms

Views

35

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

Copy link to clipboard

Copied

You can do it using this code as the field's custom Validation script:

 

if (event.value) {
	var f = event.target;
	var found = false;
	for (var i=0; i<f.numItems; i++) {
		if (f.getItemAt(i, false)==event.value) {found = true; break;}
	}
	if (!found) f.insertItemAt({nIdx: -1, cName: event.value});
}

 

The new item will be added to the list when the user exits the 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
Community Beginner ,
Jul 17, 2022 Jul 17, 2022

Copy link to clipboard

Copied

That works, except that the custom text becomes the new default, rather than the blank space default. My form reset button does not clear the box either, using the reset form action. The box is checked in the select list for form reset action.

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
community guidelines
Adobe Community Professional ,
Jul 17, 2022 Jul 17, 2022

Copy link to clipboard

Copied

LATEST

Interesting, I did not anticipate that to happen... To fix it, change this line:

if (!found) f.insertItemAt({nIdx: -1, cName: event.value});

To:

if (!found) {
	f.insertItemAt({nIdx: -1, cName: event.value});
	f.defaultValue = f.getItemAt(0, false);
}

 

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