Autocomplete and custom _renderItemData

Autocomplete and custom _renderItemData

Hi 

I have tried to modifu format of item using _renderItemData (or _renderItem) and used with remote source , it works fine till user press Arrow up/down and i get error:

Uncaught TypeError: Cannot read property 'value' of undefined L:6460


I have value field in my JSON source, when i remove _renderItemData , it works fine? 

Thanks
P


  1. $.widget( "custom.beachcomplete", $.ui.autocomplete, {
  2.     _renderMenu: function( ul, items ) {
  3.       var that = this,
  4.         currentCategory = "";
  5.       $.each( items, function( index, item ) {
  6.         if ( item.category != currentCategory ) {
  7.           ul.append( "<li class='ui-autocomplete-category'>" + item.category + "</li>" );
  8.           currentCategory = item.category;
  9.         }
  10.         that._renderItemData( ul, item );
  11.       });
  12.     },
  13.     _renderItemData: function( ul, item ) {
  14.          item.name = item.name.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + $.ui.autocomplete.escapeRegex(this.term) + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<strong>$1</strong>");
  15.          return $("<li></li>")
  16.          .data("item.autocomplete", item)
  17.          .append( "" + item.name + " (" + item.state + ")" )
  18.          .appendTo(ul);
  19.     }
  20. });