jquery UI combobox autocomplete empty value detection

jquery UI combobox autocomplete empty value detection

HI,
I am using jquery UI combobox autocomplete and the issue is that when i select an option from the combo box and then i edit that value(or even if set it to empty) still during form submission, the value at the time of edition is appearing. For example, in the combobox, say the value is 'abc123' and if i edit it to say 'abc' or set it to empty, during form submission, still the value 'abc123' is going. Can any one suggest how i can capture the value that is entered in the combobox(in this case edited value abc)? Below is my code.

  1.  (function( $ ) {
  2. $.widget( "ui.combobox", {
  3. _create: function() {
  4. var self = this;
  5. var select = this.element.hide(),
  6. selected = select.children( ":selected" ),
  7. value = selected.val() ? selected.text() : "";
  8. var input = $( "<input>" )
  9. .insertAfter( select )
  10. .val( value )
  11. .autocomplete({
  12. delay: 0,
  13. minLength: 0,
  14. source: function( request, response ) {
  15. var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
  16. response( select.children( "option" ).map(function() {
  17. var text = $( this ).text();
  18. if ( this.value && ( !request.term || matcher.test(text) ) )
  19. return {
  20. label: text.replace(
  21. new RegExp(
  22. "(?![^&;]+;)(?!<[^<>]*)(" +
  23. $.ui.autocomplete.escapeRegex(request.term) +
  24. ")(?![^<>]*>)(?![^&;]+;)", "gi"
  25. ), "<strong>$1</strong>" ),
  26. value: text,
  27. option: this
  28. };
  29. }) );
  30. },
  31. select: function( event, ui ) {
  32. ui.item.option.selected = true;
  33. //select.val( ui.item.option.value );
  34. self._trigger( "selected", event, {
  35. item: ui.item.option
  36. });
  37.                                                         self.element.trigger('change');
  38. },
  39. change: function( event, ui ) {
  40. if ( !ui.item ) {
  41. var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( $(this).val() ) + "$", "i" ),
  42. valid = false;
  43. select.children( "option" ).each(function() {
  44. if ( this.value.match( matcher ) ) {
  45. this.selected = valid = true;
  46. return false;
  47. }
  48. });
  49. if ( !valid ) {
  50. // remove invalid value, as it didn't match anything
  51. $( this ).val( "" );
  52. select.val( "" );
  53. return false;
  54. }
  55. }
  56. }
  57. })
  58. .addClass( "ui-widget ui-widget-content ui-corner-left" );

  59. input.data( "autocomplete" )._renderItem = function( ul, item ) {
  60. return $( "<li></li>" )
  61. .data( "item.autocomplete", item )
  62. .append( "<a>" + item.label + "</a>" )
  63. .appendTo( ul );
  64. };

  65. $( "<button type=button>&nbsp;</button>" )
  66. .attr( "tabIndex", -1 )
  67. .attr( "title", "Show All Items" )
  68. .insertAfter( input )
  69. .button({
  70. icons: {
  71. primary: "ui-icon-triangle-1-s"
  72. },
  73. text: false
  74. })
  75. .removeClass( "ui-corner-all" )
  76. .addClass( "ui-corner-right ui-button-icon" )
  77. .click(function() {
  78. // close if already visible
  79. if ( input.autocomplete( "widget" ).is( ":visible" ) ) {
  80. input.autocomplete( "close" );
  81. return;
  82. }

  83. // pass empty string as value to search for, displaying all results
  84. input.autocomplete( "search", "" );
  85. input.focus();
  86. });
  87. }
  88. });
  89. })(jQuery);

  90.             
  91. $(function() {
  92. $("#combobox").combobox();
  93. });