index.js
function( option ) {
        if ( option ) {
          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 };
          for (var i=0; i < context.options.length; i++) {
            if ( option_name === context.options[i]['label'].toLowerCase() ) {
              matching_option = context.options[i];
              break;
            }
          };
          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 );
          }
        }
      }
function( option ) {
        if ( option ) {
          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 };
          for (var i=0; i < context.options.length; i++) {
            if ( option_name === context.options[i]['label'].toLowerCase() ) {
              matching_option = context.options[i];
              break;
            }
          };
          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 );
          }
        }
      }
function ( option ) { if ( option ) { 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 } ; for ( var i = 0 ; i < context . options . length ; i ++ ) { if ( option_name === context . options [ i ] [ 'label' ] . toLowerCase ( ) ) { matching_option = context . options [ i ] ; break ; } } ; 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 ) ; } } }
update the select field value using either selected option or current input in the text field
update the select field value using either selected option or current input in the text field