Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

selected property doesn't work #25

Closed
ghost opened this issue Feb 27, 2014 · 7 comments
Closed

selected property doesn't work #25

ghost opened this issue Feb 27, 2014 · 7 comments
Assignees
Labels

Comments

@ghost
Copy link

ghost commented Feb 27, 2014

Here's a JS Fiddle demo that demonstrates the problem described below.

I tried setting the following as the source JSON

source: [
    {"label":"bank1","value":3},
    {"label":"bank2","value":5},
    {"label":"bank3","value":6, "selected": "selected"}
]

But the 3rd option wasn't selected. I also tried

source: [
    {"label":"bank1","value":3},
    {"label":"bank2","value":5},
    {"label":"bank3","value":6, "selected": true}
]

But this didn't work either. None of the following work either:

source: [
    {"label":"bank1","value":3},
    {"label":"bank2","value":5},
    {"label":"bank3","value":6}
],
selected: 2
source: [
    {"label":"bank1","value":3},
    {"label":"bank2","value":5},
    {"label":"bank3","value":6}
],
selected: 6
source: [
    {"label":"bank1","value":3},
    {"label":"bank2","value":5},
    {"label":"bank3","value":6}
],
selected: "bank3"
@dnasir dnasir self-assigned this Mar 3, 2014
@dnasir dnasir added the bug label Mar 3, 2014
@dnasir
Copy link
Owner

dnasir commented Mar 3, 2014

@domurtag

Thanks for the report.

Apparently the plugin is trying to set the selected item too early in the initialisation process, even before the Ajax requests have had a chance to fire (if needed).

I'll commit a fix soon.

dnasir added a commit that referenced this issue Mar 3, 2014
* Moved initial select to a later phase of the initialisation process.
@dnasir
Copy link
Owner

dnasir commented Mar 3, 2014

@domurtag

I've updated your jsfiddle: http://jsfiddle.net/Qxaa9/1/

Please confirm that the problem has been solved. I'll merge it into the master branch once I get confirmation. Thanks.

@ghost
Copy link
Author

ghost commented Mar 3, 2014

Your example works, but if I set the selected value in the JSON it doesn't work. I'm not sure what value I should use for the selected property (the docs don't specify) but I guess it's one of these:

http://jsfiddle.net/Qxaa9/2/
http://jsfiddle.net/Qxaa9/3/
http://jsfiddle.net/Qxaa9/4/

dnasir added a commit that referenced this issue Mar 4, 2014
* Added logic to set the selected item when source is an array.
@dnasir
Copy link
Owner

dnasir commented Mar 4, 2014

@domurtag

Apparently I missed that one. Fixed in dev. The method to set the selected item when providing an array as data source is by setting selected: true

@ghost
Copy link
Author

ghost commented Mar 4, 2014

Is it safe to use the dev branch or should I wait until the fix is merged to master?

@dnasir
Copy link
Owner

dnasir commented Mar 4, 2014

@domurtag I'll merge this into the master branch soon.

@dnasir dnasir closed this as completed Mar 4, 2014
@ghost
Copy link
Author

ghost commented Mar 4, 2014

Thanks for fixing this, it might be worth mentioning in the docs that the value of the selected property should be true

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

No branches or pull requests

1 participant