Skip to content

Commit

Permalink
Merge pull request #26 from dontangg/only-change-when-changed
Browse files Browse the repository at this point in the history
Only fire the change event when the value actually changes
  • Loading branch information
Jamie Appleseed committed Dec 14, 2011
2 parents b41a3f1 + 3c998d6 commit c1631df
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 c1631df

Please sign in to comment.