cancel
Showing results for 
Search instead for 
Did you mean: 

Deselect default value in listbox

0 Kudos

All,

Apologies in advance for how basic a question this is - I don't know why my solution is not working.

We are on DS 1.5.

I have a listbox (Multiple selections = false, enabled = true)  that is populated on startup via the following script.

POPUP_1.show();

var BWRoles = CONNECTION_1.getRootFolders(DataSourceBrowseType.ROLES);

BWRoles.forEach(function(element, index) {

  LISTBOX_2.addItem(index + "", "["+element.name+"] "+element.description);

});

LISTBOX_2.setSelectedValue("");

The last line, to my knowledge and per this post ( http://scn.sap.com/thread/3529413 ), should "select" (blank) as a selected value, resulting in no highlighted values.  However, this is not functioning as expected. I have tried selecting both "" and various strings not in the list ("1",etc.), to no avail.  The only solution that has produced any results has been adding a blank "item" to the end of the list and selecting it.  However, this is still not optimal, as it results in a blank, selected row at the beginning/end of my list.

Does anyone have any thoughts as to what I could be missing here?  I have experimented with both setSelectedValue () and setSelectedValues(), as well as changing the "multiple selections" parameter for LISTBOX_2.

Thanks!

Scott

Accepted Solutions (0)

Answers (3)

Answers (3)

james_batchelor2
Active Participant
0 Kudos

I ended up creating a Blank value entry with "" text on the last line and setting this value.

The list box has a wide empty line highlighted, but at least the primary values are not selected.

I also put a trap around the List box onselect event to make sure nothing happens if the user happens to hit the blank line.

I am surprised the set "" doesn't work or that there is not a SetIndex to set it to -1 (nothing selected)

james

Former Member
0 Kudos

Hi Scott Taylor

This looks weird, LISTBOX.setSelectedValue(""); will deselect the item before.. But it is not working now.

So I thought of various workarounds and you can easily achieve this with CSS. The idea is to make the highlighted color same as the background color .

I have one CSS class a and another css class b

When class a is applied my listbox will be

When class B is applies my listbox will be like  (deselected)

So by default i will use listbox to be on css class b and when list box is clicked i will change the listbox to class a.

CSS scripts -

.a.sapUiLbx

{

background: #282828;

scrollbar-arrow-color:#225e84;

scrollbar-base-color:#ebebff;

scrollbar-darkshadow-color:#225e84;

scrollbar-face-color:#225e84;

scrollbar-highlight-color:#ebebff;

}

.a.sapUiLbx li{

background:#282828;

color:#FFFFFF;

}

.a.sapUiLbxStd > ul > .sapUiLbxISel>span, .sapUiLbxstd > ul > .span

{

color:#000000;

background:#FFC000;

}

.b.sapUiLbx

{

background: #282828;

scrollbar-arrow-color:#225e84;

scrollbar-base-color:#ebebff;

scrollbar-darkshadow-color:#225e84;

scrollbar-face-color:#225e84;

scrollbar-highlight-color:#ebebff;

}

.b.sapUiLbx li{

background:#282828;

color:#FFFFFF;

}

.b.sapUiLbxStd > ul > .sapUiLbxISel>span, .sapUiLbxstd > ul > .span

{

color:#FFFFFF;

background:#282828;

}

When your class is b (deselected) write a if loop to not to pass the values as a filter to your data sources.

I hope this helps.

- Karthik S

Former Member
0 Kudos

Hi Scott,

To my knowledge, it is not possible to disable the default selection for a single-select List Box.

Instead, you could use a workaround to simulate a single-select List Box having no default selections. Use a copy of LISTBOX_2, say LISTBOX_3, and set Multiple selections = true. This List Box should overlap LISTBOX_2.

Use the following script on Startup of the application:

LISTBOX_3.setSelectedValue("");

And the following script on selection of LISTBOX_3:

LISTBOX_3.setVisible(false);

LISTBOX_2.setSelectedValue(LISTBOX_3.getSelectedValue());

Hope this helps.

Regards,

Anuraag

0 Kudos

Sorry for my late return to this conversation - thanks both of you! 

I decided the easiest workaround was simply to use a button in combination with the listbox instead of using "on select"

Thanks though!

Scott