Permalink
Browse files

Merge pull request #26 from dontangg/only-change-when-changed

Only fire the change event when the value actually changes
  • Loading branch information...
2 parents b41a3f1 + 3c998d6 commit c1631df8742119b40537b8bcbefe9292233f8518 @JamieAppleseed JamieAppleseed committed Dec 14, 2011
Showing with 8 additions and 3 deletions.
  1. +8 −3 jquery.select-to-autocomplete.js
@@ -210,7 +210,10 @@ THE SOFTWARE.
// update the select field value using either selected option or current input in the text field
var update_select_value = function( option ) {
if ( option ) {
- context.$select_field.val( option['real-value'] );
+ if ( context.$select_field.val() !== option['real-value'] ) {
+ context.$select_field.val( option['real-value'] );
+ context.$select_field.change();
+ }
} else {
var option_name = context.$text_field.val().toLowerCase();
var matching_option = { 'real-value': false };
@@ -220,15 +223,17 @@ THE SOFTWARE.
break;
}
};
- context.$select_field.val( matching_option['real-value'] || '' );
+ if ( context.$select_field.val() !== matching_option['real-value'] ) {
+ context.$select_field.val( matching_option['real-value'] || '' );
+ context.$select_field.change();
+ }
if ( matching_option['real-value'] ) {
context.$text_field.val( matching_option['label'] );
}
if ( typeof context.settings['handle_invalid_input'] === 'function' && context.$select_field.val() === '' ) {
context.settings['handle_invalid_input']( context );
}
}
- context.$select_field.change();
}
// jQuery UI autocomplete settings & behavior
context.$text_field.autocomplete({

0 comments on commit c1631df

Please sign in to comment.