Skip to content

Selected value not appearing after refresh() #106

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

Closed
awead opened this issue Oct 22, 2013 · 2 comments
Closed

Selected value not appearing after refresh() #106

awead opened this issue Oct 22, 2013 · 2 comments

Comments

@awead
Copy link

awead commented Oct 22, 2013

I'm in a Rails+jQuery app, building my options for combobox using some json that I grab via ajax. If my field already has an existing value, I can't get that value to be set within the box.

I'm currently trying to add the "selected" attribute when I populate the list of options if it matches the current value:

if (json.value == current_value) {
  html = '<option value="'+json.value+'" selected>'+json.text+'</options>';
}
else {
  html = '<option value="'+json.value+'">'+json.text+'</options>';
}
$('#field select').data('combobox').refresh();

But that's not working. Is this the same as #75 ?

Is there another solution, perhaps passing in the selected value when combobox is initialized?

Thanks in advance!

@tomislavmitic2012
Copy link

Have you tried this:
$('#field select').val('0');
$('#field select').data('combobox').refresh();

@thephw
Copy link
Collaborator

thephw commented May 13, 2014

This should work as long as you are calling the refresh at the end.
Seems to work in the latest version.

If you want a simple test you can fork and setup your scenario to the test app. It's just a rackup that can be deployed to heroku for free.

https://github.com/wiserstudios/bootstrap_combobox_test

@thephw thephw closed this as completed May 13, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants