Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery _renderItem not being called

I am trying to create a custom ui-menu-item element using the _renderItem function but after may tries I can't get the function to even be called. The auto-complete is working but it is like the _renderItem function is not there. Here is my script scction

<script language="Javascript" type="text/javascript">
    function split( val ) {
    return val.split( /,\s*/ );
} 
function extractLast( term ) {
    return split( term ).pop();
}

$j(document).ready(function() { //START of ready function
$j( "#custom-report" )
.autocomplete({
source: function( request, response ) {
$j.getJSON( "<?=$this->url(array("controller"=>"report", "action"=>"custom-autocomplete"))?>", {
term: extractLast( request.term )
}, response );
},

search: function() {
//Place holder
},

focus: function (event, ui) {
       // Prevent the default focus behavior.
       event.preventDefault();
},

select: function( event, ui ) {
var terms = split( this.value );
terms.pop();
terms.push( ui.item.value );
this.value = terms.join( ", " );
return false;
}
}).data("autocomplete")._renderItem = function (ul, item) {
        return $("<li />")
            .data("item.autocomplete", item)
            .append("This is the text")
            .addClass("tip")
            .attr("desc", "This is the description")
            .appendTo(ul);
    };
}); //END of ready function
</script>

Anyone have any idea why this is not working?

like image 819
Alex Avatar asked Dec 12 '25 18:12

Alex


1 Answers

I ended up having to do this

$.ui.autocomplete.prototype._renderItem = function (ul, item) {
    return $("<li></li>")
     .data("item.autocomplete", item)
    .addClass("tip ui-menu-item")
    .append("<a>" + item.label + "</a>")
    .attr("desc", item.description) /* This is the filed that started the whole thing */
    .attr("role", "presentation")
    .appendTo(ul);
};
like image 176
Alex Avatar answered Dec 15 '25 08:12

Alex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!