Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery Autocomplete: formatItem doesn't work

We've put frustrating hours into the attempt to get a remarkably simple script to work (and everyone else seems to be successful). Finally, we want to create an autosuggest textbox using JQuery that writes the value of a selected text into a hidden field, but this question isn't about that because even the first step fails (but working sample code regarding that is very welcome).

For some obscure reason, formatItem (and the other formatting functions) is not executed. What are we misunderstanding?

Any help is HIGHLY appreciated.

Here's the code (stripped of anything not needed for the example):

<html>
<head>
<title>Why o why?</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js"></script>
    <script type="text/javascript">
    $(function() {
        var s = ["a", "b", "ab"];
        $("#txtSearch").autocomplete({
            source: s,
            formatItem: function(row, i, n) { return "whatever" },
            minLength: 1
        });
    });
    </script>
</head>
<body>
    Search <input id="txtSearch" type="text" />
</body>
</html>

The autosuggest function as such is working in any browser, but no browser fires formatItem.

like image 248
Olaf Avatar asked Jan 22 '23 12:01

Olaf


1 Answers

Those methods are all deprecated in the version that is bundled into the jQuery UI. Check this migration guide to learn more about how the old formatItem, formatMatch etc. could now be implemented.

like image 152
Hari Pachuveetil Avatar answered Jan 28 '23 06:01

Hari Pachuveetil