jQuery UI autocomplete- no results message

前端 未结 4 559
一个人的身影
一个人的身影 2020-12-02 01:59

I\'m trying to have a \"No Results\" message appear in the dropdown menu if there are no results. So for instance, if I type in \"ABCD\" into the text field, and there is n

4条回答
  •  失恋的感觉
    2020-12-02 02:10

    if (!ui.content.length) {
        var noResult = { value:"",label:"No results found" };
        ui.content.push(noResult);
        //$("#message").text("No results found");
    } 
    

    Fiddle

    http://jsfiddle.net/J5rVP/129/

    Update

    Put the code at the end of your auto-complete setup just after select: function (event, ui) {..}

        ..........
        minLength: that.options.minLength,
        select: function (event, ui) {
            reRenderGrid();
        },   //HERE - make sure to add the comma after your select
        response: function(event, ui) {
            if (!ui.content.length) {
                var noResult = { value:"",label:"No results found" };
                ui.content.push(noResult);
            }
        }
    });
    

提交回复
热议问题