diff --git a/js/jquery.combobox.js b/js/jquery.combobox.js index 772a844e..63b0cea6 100644 --- a/js/jquery.combobox.js +++ b/js/jquery.combobox.js @@ -48,17 +48,29 @@ self._trigger('selected', event, { item: ui.item.option }); + select.children('option').each(function() { + if ($(this).text().toLowerCase() === $(ui.item.option).text().toLowerCase()) { + $(this).attr('selected', 'selected'); + } else { + $(this).removeAttr('selected'); + } + }); + select.trigger('change'); }, change: function( event, ui ) { - if ( !ui.item ) { - var matcher = new RegExp( '^' + $.ui.autocomplete.escapeRegex( $(this).val() ) + '$', 'i' ), + if(!ui.item) { + var matcher = new RegExp( '^' + $.ui.autocomplete.escapeRegex($(this).val()) + '$', 'i'), valid = false; self.input.val($(this).val()); //self.input.trigger('change'); select.children('option').each(function() { - if ( $( this ).text().match( matcher ) ) { + if ($(this).text().match(matcher)) { this.selected = valid = true; - return false; + $(this).attr('selected', 'selected'); + select.trigger('change'); + //return false; + } else { + $(this).removeAttr('selected'); } }); if ( !self.options['editable'] && !valid ) { @@ -67,6 +79,9 @@ select.val( "" ); input.data('autocomplete').term = ''; return false; + } else if(!valid) { + select.append(''); + select.trigger('change'); } } }