Show "no results found" if JQuery Autocomplete has no results

instead of empty list..
Also, obviously you should not be able to select it into the search input..
can someone tell me how to do it?
Thanks, Aryeh.
tuchfeldAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tuchfeldAuthor Commented:
Here is the javascript I use.
and please remember that "no results found" SHOULD NOT be able to be selected.
Thanks, Aryeh.
$(document).ready(function() {
  $("#string").autocomplete({
        source: function(request, response) {
          var URL = "/BOOKS_Search.aspx?search_in=" + getBooks();
          $.getJSON(URL, request, function(data) {
			    var parsed = [];
			    var rows = data;
			    for (var i=0; i < rows.length; i++) {
				    var row = $.trim(rows[i]['search_res']);
				    if (row) {
					    parsed[parsed.length] = {
						    label: row + " (" + $.trim(rows[i]['_n']) + ")",
						    value: row
					    };
				    }
			    }
		      response(parsed);
          });
        },
		scroll: true,
		scrollHeight: 180,
		minChars: 1,
		matchSubset: false
	});
  $("input:checkbox[name='SearchInBook1']").bind("click", function() {
     $("#string").autocomplete("search");
  });
  $("input:checkbox[name='SearchInBook2']").bind("click", function() {
     $("#string").autocomplete("search");
  });
});

Open in new window

0
chaitu chaituCommented:
can't you write like this  .

if (!data || data.length == 0) {  
           $('#string).val('No Matches');

     }

http://stackoverflow.com/questions/3403574/no-results-message-on-jquery-autocomplete
http://stackoverflow.com/questions/849415/handling-no-results-in-jquery-autocomplete
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

chaitu chaituCommented:
Is this what you are looking

$(document).ready(function() {
  $("#string").autocomplete({
        source: function(request, response) {
          var URL = "/BOOKS_Search.aspx?search_in=" + getBooks();
          $.getJSON(URL, request, function(data) {
			    var parsed = [];
			    var rows = data;

		if (!data || data.length == 0) {  
		       $('#string').val('No Results Found'); 
		   } 
		else
			 {  
			 for (var i=0; i < rows.length; i++) {
				    var row = $.trim(rows[i]['search_res']);
				    if (row) {
					    parsed[parsed.length] = {
						    label: row + " (" + $.trim(rows[i]['_n']) + ")",
						    value: row
					    };
				    }
			    }
		      response(parsed);

			  }
          });
        },
		scroll: true,
		scrollHeight: 180,
		minChars: 1,
		matchSubset: false
	});
  $("input:checkbox[name='SearchInBook1']").bind("click", function() {
     $("#string").autocomplete("search");
  });
  $("input:checkbox[name='SearchInBook2']").bind("click", function() {
     $("#string").autocomplete("search");
  });
}); 

Open in new window

0
tuchfeldAuthor Commented:
I have tried it..
but it replaces the <INPUT> field value with the text 'No Matches'.
This is not wht I request.
I'd like that
1) 'No Matches' will apear as the ONLY CHOICE IN LIST (of the autocomplete choices), and
2) if you select it - IT WILL NOT APEAR IN THE <INPUT> box (you cannot select it) otherwise it overrides the text you have entered and you cannot re-edit it.
I hope I'm understood.
Thanks, Aryeh.
0
chaitu chaituCommented:
0
tuchfeldAuthor Commented:
here is what I expect.
and again if you click on the choice "no results found" it WILL NOT change the text "blabal".
OK?
to-ExEx.GIF
0
chaitu chaituCommented:
i assume that no results found text will print below textbox;is it a label or a button("no results found")??

my assumption is if you type anything on texbox if results are not there it will print ""no results found" text below the text box.if user types again in text box for the search results.

see the example i posted above.
0
tuchfeldAuthor Commented:
I think the solution should be like this code..
otherwise IF YOU CLICK on the choice "No results found" it will replace the <INPUT> text ("blabal")
and I don't want this to happen. OK?
but what is the id of the element (".someElement" in my code)?
if (!data || data.length == 0)
{
  parsed[0] = {
    label: "No Results found."
  };
  $('.someElement').attr('disabled', 'disabled');
}
else
{
  $('.someElement').attr('disabled', '');
  // ...

Open in new window

0
chaitu chaituCommented:
how can you click choice 'No Results found";its just a label.its  not a button or a link.
0
tuchfeldAuthor Commented:
Well, I've used this exact code shown above. and once I click on this choice it replaces the <INPUT> text  to 'No Results found".
0
tuchfeldAuthor Commented:
Here is a possible solution I got:
var no_results;
$(document).ready(function() {
  $("#string").autocomplete({
  // ...
    no_results = !data || data.length == 0;
    if (no_results)
    {
      parsed[0] = {
        label: "No Results found."
      };
    }
    else
    {
      // ...


  $("#string").bind("autocompleteselect", function(event, ui) {
    if (no_results) return false;
  });

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
chaitu chaituCommented:
this is exactly they do that i posted above links.

"No Results found." is just a label ;user cannot click on the labels.
0
tuchfeldAuthor Commented:
You have posted about 10 links already (I counted) which one of them?
0
tuchfeldAuthor Commented:
As I experienced, using label: DOES NOT MEAN you cannot select it.
0
chaitu chaituCommented:
normally labels will be used as displaying the text.if you want to can write click event on labesl as well.but for your scenario its not required.if no records are found just we will show it as a Label,
0
tuchfeldAuthor Commented:
sorry chaituu, I'm not usually giving up supporters assistance but your solution using label in my code made it selectable and therefore bind("autocompleteselect"... was necessary.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.