sparkbox / Custom-Selectbox

Select box UI replacement
70 stars 25 forks source link

jquery form selectors not working #3

Closed danielinniss closed 12 years ago

danielinniss commented 13 years ago

When you try and use jquery to change the selected item (such as a reset button) nothing happens. Sparkbox seems to break something. Even the underlying select lists do not change.

I have tested my functions with sparkbox on and off. Works when off but is broken when sparkbox is on

reproduce by trying to set the value of a select list while using sparkbox $("select#elementid").val('a value')

davidray commented 13 years ago

This is broken for me too. You can make it change by changing the value of the hidden input that follows the select, but this seems like badness to me.

danielinniss commented 13 years ago

Really? that didnt seem to work for me, changinf the underlying select list. my entire script is built to do just that. I'll give it a go

davidray commented 13 years ago

Here's the workaround I came up with:

$("#select_id").next().val("Female"); $("#select_id").val("Female");

The first one changes the value that is displayed. The second one changes the value that is submitted with the form.

bwebsites commented 12 years ago

$('#select_id').val(""); $('#select_id').trigger('change');

robtarr commented 12 years ago

Yes, the change event does not fire on the select box unless there is an actual browser event. So, instead of adding another method, the preferred method is to change the value of the original select box and then manually trigger the change event, something like this:

$originalSelect.val(newValue).trigger('change');