Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>OK, Solved it, thanks to a little inspiration from Karim, I decided it doesn't need to be the elementID, I just need to be able to specify different reference/option for each autocomplete which I achieved with the following:</p> <pre><code>$("#input1").autocomplete({ source: source1, format: format1 /* This is my planted reference */ }); $("#input1").autocomplete({ source: source2, format: format2 }); </code></pre> <p>RenderMenu becomes:</p> <pre><code>$.ui.autocomplete.prototype._renderMenu: function( ul, items ) { var self = this; $.each( items, function( index, item ) { if ( this.options.format == 'format1' ) { self._renderItemCustom1( ul, item ); } else if ( this.options.format == 'format2' ) { self._renderItemCustom2( ul, item ); } else { self._renderItem( ul, item ); } }); }; </code></pre> <p>And I can specify infinite _RenderItem's like so as long as they are specified within _renderMenu:</p> <pre><code>$.ui.autocomplete.prototype._renderItemCustom1: function( ul, item ) { return CUSTOM FORMATTING; } </code></pre> <p>It's also perhaps better than relying on element ID, as it means the same custom _renderItem can be used for multiple inputs with different IDs but the same output method.</p> <p>EDIT: To make it a little more efficient and not bloat _renderMenu I recoded it:</p> <pre><code>$.ui.autocomplete.prototype._renderMenu = function( ul, items) { var self = this; if ( typeof this.options.format == 'undefined' ) { $.each( items, function( index, item ) { self._renderItem( ul, item ); }); } else { var fname = 'self._renderItem' + this.options.format + '( ul, item )'; $.each( items, function( index, item ) { eval(fname); }); } } </code></pre> <p>This new code means you do not have to rewrite _renderMenu for each new _renderItem method, instead it will execute _renderItemFORMATNAME automatically if </p> <pre><code>format: FORMATNAME </code></pre> <p>is specified. Although for my original example</p> <pre><code>$.ui.autocomplete.prototype._renderItemCustom1 becomes: $.ui.autocomplete.prototype._renderItemformat1 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload