Skip to content
This repository has been archived by the owner on May 21, 2021. It is now read-only.

w11k-select-options with object as the selected model? #17

Closed
amarkitanis opened this issue Jan 19, 2015 · 5 comments
Closed

w11k-select-options with object as the selected model? #17

amarkitanis opened this issue Jan 19, 2015 · 5 comments

Comments

@amarkitanis
Copy link

Hi,

While this works fine:

     w11k-select-options="book.value as book.label for book in widget.bookSet"
     ng-model="widget.selectedBooks"

I want to be able to reference the actual book object in my widget.selectedBooks model.

An issue I have found is that I have cases where my bookSet array has objects where the book.value is the same (i.e not unique) and this creates problem with option.hash - therefore not displaying the actual dropdown because of ng-repeat dupes.

So rather than have an array of strings in selectedBooks, I want to have an array of objects. This would solve the issue of the ng-repeat problem with the option.hash track by and also cases whereby I want to deal with the whole object in my model and not just the string value.

When I try that, I don't see anything in the dropdown. Do I need to change something?

Thanks,
Andreas

@kaihenzler
Copy link
Member

Hello Andreas,

what do you mean by

When I try that, I don't see anything in the dropdown. Do I need to change something?

did you do the following? Or what exactly did you try?

w11k-select-options="book as book.label for book in widget.bookSet"
ng-model="widget.selectedBooks"

You should be able to push the whole book-Object into your selectedBooks-Array by using the Syntax mentioned above.

Greetings

@amarkitanis
Copy link
Author

Yes I tried this, and it didn't work. The only one that worked was:

w11k-select-options="book.label for book in widget.bookSet"

but nothing was selected by default (Which is the behaviour that I want)

@amarkitanis
Copy link
Author

actually no -

book as book.label for book in widget.bookSet works, but they none of the options are ticked/selected.

If I instead have
book.value as book.label for book in widget.bookSet, then all the options are ticked/selected which is what I want but I want but the model is not what I want

@pburgmer
Copy link
Collaborator

Hi Andreas,

You're right, there are hash collisions. I created a jsbin to reproduce the bug: http://jsbin.com/cuzanifoqo/1/edit?js,output

With 1, 2, 3 and 4 as values it does not work. But it works with 11, 22, 33, and 44 as values with unchanged labels.

I created another jsbin to test the hash function: http://jsbin.com/wokifobovu/1/edit?js,output
It outputs the same hash code for all objects. Not a very good hash function implementation ... I will replace the hash function with another implementation and release a bugfix as soon as possible.

@pburgmer
Copy link
Collaborator

Hi @amarkitanis ,

If you're using w11k-select and like it, please think about giving an 'I use it' at ngmodules.org
http://ngmodules.org/modules/w11k-select

Thanks & regards,
Philipp

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants