Skip to content

How Set a value via jQuery ? #75

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
rubensedanoc opened this issue Jun 22, 2013 · 12 comments
Closed

How Set a value via jQuery ? #75

rubensedanoc opened this issue Jun 22, 2013 · 12 comments
Labels
bug Confirmed bug question Issue which pertains to how the plugin can be used

Comments

@rubensedanoc
Copy link

I need select a val from options via jQuery

@danielfarrell
Copy link
Owner

Huh, well I thought that if you had the select element you should be able to set it's value and trigger change and that would make the combobox change, but that does not appear to be working anymore. I'll mark this as a bug because I want that behavior.

@rubensedanoc
Copy link
Author

ok Daniel, thank you very much for this plugin, I am using it in my project.
Best Regards.

@ngoodwin14
Copy link

I am able to select an option by text (i.e. the text is the variable consFrame) programmatically with this approach:

           $('#custom_menu_obj li').each(function(i, li) {
                var $item = $(li); 

               if ($item.text() == consFrame) {
                    $item.addClass('active');
                } else {
                    $item.removeClass('active');
                }

            })
           $('#select_obj').combobox('select');

where custom_menu_obj is the combobox menu object (I had to add the id attr to your js). However there is a catch. This only works if you have previously opened the target combobox, since the 'ul' and all its children do not load into the DOM until they have been clicked on.

@KasperJacobsen
Copy link

I need this also, I can set the value and retrieve it with $('.original-select-element').val(); but it doesn't show up in the combobox.

Any news on this bug?

@ngoodwin14
Copy link

I am still waiting on an update for this as well. I have tried to solve it myself, but have been unsuccessful. One workaround that I have found is to call the 'toggle' twice on document/DOM ready - which forces the combobox to load into the DOM, then you can use the script I included above. Not elegant, but it works!

Well, almost works, the combobox has some strange behaviour (two clicks on the remove to completely clear the box! sigh)

@danielfarrell
Copy link
Owner

This is not a use case I have at the moment, so one of you may have to fix it if you want it soon.

My first instinct is that I'd do it is to listen for the change event on the select box and update the text input with the new value. I think the reason that didn't happen was because I think we trigger change on the select when you choose one. That would be circular.

What I'd suggest pursuing is to add a method that you could call to update that could do all the necessary things. $('element').combobox('update', value) or something like that.

@ngoodwin14
Copy link

I have tried that approach (as best I could), however the issue is that the < ul > and its children (i.e. < li >') doesn't get loaded into the DOM until the combobox is manually selected by the user. Because of this, I don't see a way to add the class="active" to a desired < li > in the dropdown at the document ready point before the user has a chance to interact with the page.

Am I missing something?

@danielfarrell
Copy link
Owner

I do that for select boxes that have a value selected already. You should look in that code and see what happens there. You shouldn't have to do that manually.

@thephw
Copy link
Collaborator

thephw commented May 13, 2014

This is currently how I would do it:

$("myComboBoxSelector").val('TheOptionValue')
$("myComboBoxSelector").data('combobox').refresh()

@thephw thephw closed this as completed May 13, 2014
@potocnik
Copy link

Refreshing combobox data works for me too.

@sliekens
Copy link

Refreshing works but not for options that have an empty value.

<select id="example">
  <option value="">No Value</option>
  <option value="1">A Value</option>
</select>
$('#example').combobox();

// Works
$('#example').val('1');
$('#example').data('combobox').refresh();

// Doesn't work
$('#example').val('');
$('#example').data('combobox').refresh();

// Doesn't work
$('#example').val(null);
$('#example').data('combobox').refresh();

// Doesn't work
$('#example').val(undefined);
$('#example').data('combobox').refresh();

@mwaleedraza
Copy link

$("myComboBoxSelector").data('combobox').refresh()
Run this after updating the List otherwise it will not show the updated list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug question Issue which pertains to how the plugin can be used
Projects
None yet
Development

No branches or pull requests

8 participants