jQuery autocomplete and event concept

jQuery autocomplete and event concept

The jquery website gave the autocomplete code I needed, which specifically is autocomplete for a comma separated list of words.  But when I use the autocomplete code something does not work.  I am building a single page application where divs are being swapped in and out.  

When I reach this function, I confirmed through chrome dev tools that my array of possible words has been generated after consuming a web service I built.  I must be missing something conceptually since I don't see anything wrong.  'allNames' is the autocomplete source array.  'myTextField' is the id of my input text field. I have a click listener whose handler is autocomplete, which uses the helper functions split and extractVals. Here's my code snippet:

  1.          allNames.sort();
  2. /* get all tokens, delimited by ", " */
  3.         function split( val ) {
  4.           return val.split( /,\s*/ );
  5.         }
  6.         
  7.         function extractLast( term ) {
  8.           return split( term ).pop();
  9.         }
  10.        
  11.         // start autocomplete multiple vals 
  12.         $( "#myTextField" )
  13.           .autocomplete(
  14.                       {
  15.                            minLength: 0,
  16.                            source: function( request, response ) {
  17.                            response( $.ui.autocomplete.filter(allNames, 
  18.                                                              extractLast(request.term)) 
  19.                                   );
  20.                            },
  21.                            focus: function() {
  22.                                     return false;
  23.                            },
  24.                            select: function( event, ui ) {
  25.                                     // terms is an array of tokens
  26.                                      var terms = split( this.value );
  27.                                      terms.pop();
  28.                                      terms.push(ui.item.value);
  29.                                      terms.push( "" );
  30.                                      this.value = terms.join(", ");
  31.                                      return false;
  32.                                    }
  33.                            }
  34.                          );
  35.         /* show this div in my single page app container identified by "ReplaceMe".  "htmlContent"              so far is an html string containing the textfield identified by 'myTextField' */
  36.         $("#ReplaceMe").html(htmlContent);