From 3c998d6cea24bcaca8bc0c936746141642d4679e Mon Sep 17 00:00:00 2001 From: Don Wilson Date: Wed, 14 Dec 2011 00:24:01 -0700 Subject: [PATCH] Only fire the change event when the value actually changes --- jquery.select-to-autocomplete.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/jquery.select-to-autocomplete.js b/jquery.select-to-autocomplete.js index fc44463..b9eea42 100644 --- a/jquery.select-to-autocomplete.js +++ b/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,7 +223,10 @@ 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'] ); } @@ -228,7 +234,6 @@ THE SOFTWARE. context.settings['handle_invalid_input']( context ); } } - context.$select_field.change(); } // jQuery UI autocomplete settings & behavior context.$text_field.autocomplete({