Skip to content

Commit

Permalink
Only fire the change event when the value actually changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dontangg committed Dec 14, 2011
1 parent b41a3f1 commit 3c998d6
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions jquery.select-to-autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand All @@ -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({
Expand Down

0 comments on commit 3c998d6

Please sign in to comment.