Skip to main content
Known Participant
April 15, 2021
Question

Clear List Box Selection

  • April 15, 2021
  • 3 replies
  • 2586 views

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?

 

 

This topic has been closed for replies.

3 replies

Bernd Alheit
Community Expert
Community Expert
April 15, 2021

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

And use resetForm.

Known Participant
April 15, 2021

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!

try67
Community Expert
Community Expert
April 15, 2021

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

What happens when you use it?

Known Participant
April 15, 2021

It clears the list entirely

try67
Community Expert
Community Expert
April 15, 2021

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

Nesa Nurani
Community Expert
Community Expert
April 15, 2021

Use 'clearItems()' to do that.

like this:

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

Known Participant
April 15, 2021

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.

Nesa Nurani
Community Expert
Community Expert
April 15, 2021

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.