What caveats are there when pre-selecting an entry in a listbox

This thread was migrated from an old forum. It may contain information that are no longer valid. For further assistance, please post a new question or open a support ticket from the Customer Support portal.

Currently I use the following code to set the data in a listbox:

frm….lst….masterData = masterdata; frm….lst….selectedKeys = selection;

with selection being a valid key of master data. AFAIK this should mean that the listbox is shown with element represented by selection to be selected.

So what could go wrong? What caveats exists with the use of listboxes?

Hi @Onuw Gwegowy​ ,

We have to use selectedKey instead of selectedKeys for showing the pre-selected item in listbox.

var dat = [["key1","Kony"],["key2","India"],["key2","Private"]]; this.view.lstbox123.masterData = dat; this.view.lstbox123.selectedKey = "key2";//dat[2][0]

Thanks,

@Kvwen Cvmewon​ I tried selectedKey as well. In fact, I tried selectedKey first and only move to selectedKeys when it did not work. They both don't work. There must be something else here.

Hi @Onuw Gwegowy​

I have checked in 8.1.7 version of Kony Enterprise for the code and it working fine. Can you please let us know about the plugins you are using and also the platform in which you are checking.

I will check accordingly. If possible can you please share the sample app you are working on so that I will also debug and can come to a solution.

Thanks,

@Kvwen Cvmewon​ I attached the plugin list.

Put I don't think this is an bug be replicate. This is why I asked for caveats. Well known pitfalls one can do wrong when using selectedKey. Stuff to look out for. Because I am pretty sure it works when you do everything just the right way.

For example, currently the data is filled in before the call the show() — is that OK or do I have to move it into preShow or postShow ?

Hi @Onuw Gwegowy​ ,

Can you please call the listbox code in preShow or postShow of the form.

Thanks,

@Kvwen Cvmewon​ Sure I can. Which has the better chance of working?

Also I noticed something else. Up until now i only tested with Android but now I also made a test with iOS. And to my surprise: It works with iOS.

This is kind of frustrating. Both platforms should work the same.

Hi @Onuw Gwegowy​ ,

Please call in preShow of the form. It might be because of the hot fix plugins you are using currently. Please update to the latest GA version to avoid any issues.

Thanks,

@Kvwen Cvmewon​ Tried preShow but that did not help. I also tried postShow which did not work as well. For Android. Both worked find iOS. 😞

“Please update to the latest GA” — one day before code freeze 😣

Of course the update failed:

https://hclpnpsupportdev.service-now.com/community?id=community_question&sys_id=af74d8d11b58e8142518542f0a4bcb7d&view_source=searchResult

Have not expected anything else. 😞

Update for anybody who might find this: I used numeric keys starting with "0" and that seemed to be the problem on Android. If a different key, for example “2” is used it works.

The obvious workaround would be to add a character to the keys. For example "@0", "@1", …

A more obscure workaround is the use toString. For example «selectedKey = selection.toString()». That too works.

Both workarounds are tideous and error prone.

And to answer my original question on which caveat might exist:

DON'T USE NUMERIC KEYS STARTING WITH 0 — That does not work with Android.

Another great workaround! Thank you so much @Onuw Gwegowy​ for sharing!

@Jvne Dickens​ Just checking up on my tickets I noticed that the Ticket i wrote for this problem has been closed.

But this is clearly a bug which need to be fixed and that I had a workaround and and was on holiday and hence did not respond makes no difference to the fact that this is bug.

This bug needs to be fixed — not for me because I have a workaround — but for all your other customers who do not know about the workaround and can fall for the same problem.

You should not be satisfied with “closing a ticket” and “Selected as Best” the community posting.

You should thrive to fix the bug.