Clear List Box Selection

Community Beginner ,
Apr 14, 2021 Apr 14, 2021

Copy link to clipboard

Copied

I would like to have a button that clears the selection of a bunch of list boxes.  I have tried using the following JS which works well for reseting Radio Bottons:

 

this.resetForm(["ListBox1"]);

this.resetForm(["ListBox2"]);

 

What is the equivalent Button JS code for clearing the selection of a list box?

 

 

TOPICS
JavaScript

Views

333

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 ,
Apr 14, 2021 Apr 14, 2021

Copy link to clipboard

Copied

Use 'clearItems()' to do that.

like this:

this.getField("ListBox1").clearItems();

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 ,
Apr 15, 2021 Apr 15, 2021

Copy link to clipboard

Copied

Sorry, I should have explained this better. What I was hoping to achieve is not clear the choices in the List Box that are being offered but the one that is selected.  By default, one is chosen as being selected.  I was wondering if it were possible to clear that selected default.  So that it is a clean list.  I would have put in a blank (no script) choice in the list but that cannot be done.

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 ,
Apr 15, 2021 Apr 15, 2021

Copy link to clipboard

Copied

I'm not sure what you want. You say you want to delete selected item in a List Box

try this:

var f = this.getField("List Box1");
f.deleteItemAt(f.currentValueIndices);

you can use it in a button.

But you also say you want 'clean list'. what does that mean?

Why can't you put blank? you can add it as any other value, press 'space' when adding values.

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 ,
Apr 15, 2021 Apr 15, 2021

Copy link to clipboard

Copied

This code should do it... It will revert those fields to their default selections.

What happens when you use it?

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 ,
Apr 15, 2021 Apr 15, 2021

Copy link to clipboard

Copied

It clears the list entirely

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 ,
Apr 15, 2021 Apr 15, 2021

Copy link to clipboard

Copied

I was referring to the code you posted, not the one from Nesa.

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 ,
Apr 15, 2021 Apr 15, 2021

Copy link to clipboard

Copied

One additional question, regarding the usual way that List Box selections work.  Currently, under the Options Tab within the List Box Properties there is a check box for Multiple selection.  When I multi-select the items and merge them to another Text Field they are comma separated but without a space between the comma and the next script (ie 1,2,3 rather than 1, 2, 3).  Is there a way I can create the latter?  I was wondering if placing appropriate JS within the Selection Change tab might offer a solution.  I am aware that placing a space before the listed item offers a solution however this assumes that more than one item is being selected which in some cases it isn't. 

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 ,
Apr 15, 2021 Apr 15, 2021

Copy link to clipboard

Copied

How does you merge the items?

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 ,
Apr 15, 2021 Apr 15, 2021

Copy link to clipboard

Copied

Within the merging Text Field JS I place:

 

event.value = this.getField("ListBox1").value

 

This also has the Multi-line check box selected within the Options tab.

 

ListBox1 is a list of items with the check box for Multiple selection checked within the Options tab.

 

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 ,
Apr 16, 2021 Apr 16, 2021

Copy link to clipboard

Copied

Use this code:

 

var v = this.getField("ListBox1").value;
if (typeof v=="string") event.value = v;
else event.value = v.join(", ");

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 ,
Apr 16, 2021 Apr 16, 2021

Copy link to clipboard

Copied

LATEST

Works very nice, thank you TRY67.

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 ,
Apr 15, 2021 Apr 15, 2021

Copy link to clipboard

Copied

In the properties of the list box don't select any list item.

And use resetForm.

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 ,
Apr 15, 2021 Apr 15, 2021

Copy link to clipboard

Copied

Sorry, for my ignorance.  I didn't realise that I could deselect the list box item from being a default choice by mouse clicking below the list choices in the Properties\Options tab.  Then I used the button with the below JS and it worked perfectly.

 

this.resetForm(["ListBox1"]);

 

Actually, I also discovered that if I used:

 

this.resetForm(["Group1"]);

 

the button selection cleared all the Group1 List Boxes.

 

Many 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