Clear Autocomplete data when new item is searched
Hi,
I am trying to use Autocomplete in SharePoint custom list. I have used the below code for the autocomplete functionality
- $(document).ready(function() {
- var titles = [];
- var autocomplete = $("input[title='Skill Required Field']").autocomplete({
- minLength: 3,
- source: function(request, response) {
- $.ajax({
- url: siteURL + "/_api/web/lists/getbytitle(\'MySkills\')/items?$select=Title&$filter=startswith(Title, '" + request.term + "')",
- cache: false,
- method: "GET",
- headers: {
- "Accept": "application/json; odata=verbose"
- },
- success: function(data) {
- $.each(data.d.results, function(i, result) {
- if (result.Title) {
- titles.push(result.Title)
- }
- });
- return response(titles);
- },
- error: function( data ) {
- alert('search error');
- }
- });
- },
- focus: function(event, ui) {
- return false;
- }
- });
- });
The above code works fine, but the issue is - If i search for a term and select it and if I again search for another term, then in the search results collection, the first searched result is also showing up. How to clear the search result after each record selection.
I am using jquery-1.11.3.min , jquery-ui-1.12.1