Add additional link to jquery ui autocomplete list

六月ゝ 毕业季﹏ 提交于 2020-01-21 16:13:28

问题


Sorry I couldn't find a clear solution on how to do this. I'm using jQuery UI autocomplete on a textbox that retrieves data from a database. I need to add an "Add new Venue" link to the end of the list. I want to allow users to add a new venue, if the venue they're looking for is not already in the database.

Here is my code:

$(function() {
    $("#venue").autocomplete({
        source: '<?php echo base_url();?>index.php/home/autocomplete_venue',
        minLength: 2,
        select: function(event, ui) {
            $('#venue_id').val(ui.item.id);                 
        }
    });
});

回答1:


I suppose you could add the li in one of Autocomplete's callbacks, like open:

$('#venue').autocomplete({
    open: function () {
        // If it's not already added
        if (!$('#ac-add-venue').length) {
            // Add it
            $('<li id="ac-add-venue"><a href="....">Add venue</a></li>').appendTo('ul.ui-autocomplete');
        }
    }
});

You may need to change some selectors.

Edit: Btw: there's no way that can be all your code? It's missing several closing }:s for one.



来源:https://stackoverflow.com/questions/8598098/add-additional-link-to-jquery-ui-autocomplete-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!