davecoffin / nativescript-filterable-listpicker

Apache License 2.0
44 stars 22 forks source link

selectedItem is undefined unless search box is used #15

Closed petesimard closed 6 years ago

petesimard commented 6 years ago

When I select an item the args.selectedItem returns undefined unless I use the search box first. If I use the search box (just entering a single letter, and then deleting it) and then select an item, it will correctly set the selectedItem.

<FilterableListpicker #myfilter blur="dark" hintText="Type to filter..." (itemTapped)="otherPlayerSelected($event)"></FilterableListpicker>

otherPlayerSelected(args) { var selectedPlayerName = args.selectedItem; console.log(selectedPlayerName); }

Which platform(s) does your issue occur on?

Android

Please, provide the following version numbers that your issue occurs with:

Please, tell us how to recreate the issue in as much detail as possible.

Describe the steps to reproduce it. Show a list and select an item right away, the selectedItem property will be undefined. If you use the search box, the selectedItem will be correct.

petesimard commented 6 years ago

Fixed it.

I was setting the source using:

new ObservableArray(row.player.otherPlayers)

Just setting the source to the raw array solved the issue.

davecoffin commented 6 years ago

Oh good I’m glad you figured it out. Yea, the plugin accepts a raw array, it’s not necessary to use an observable array because there’s no way it can change in front of your eyes. If you need to change the items when it’s displayed, just change the source before you call show. There’s an example in the demo.