Show autocomplete options on focus or mousover

QuestionsShow autocomplete options on focus or mousover
pcattani asked 3 years ago

I am trying to get the autocomplete options to show on first focus.

Options show when I delete all the text from a field, but not when I click into a new field.


I already have this:

$col[“editoptions”][“onfocus”] = “$( ‘#office’ ).autocomplete( { search: ”, minLength: 0 } );”;


Which shows all the options without any beginning criteria.   The problem is I can’t get the list to show as soon as the user clicks in to the field.

I investigated a few options here:


But I couldn’t get the input box to respond.


Is there a grid4php option to show autocomplete options the minute a cursor is in an input field?  Or failing that, mouseover?


Thanks in advance.

5 Answers
Abu Ghufran Staff answered 3 years ago


Instead on onfocus, try using this event on afterShowForm event. e.g. for field with name as ‘office’

$grid["add_options"]["afterShowForm"] = "function (form) 
			// for first load without focus
			$('#office').autocomplete('search', '');

			// on focus of field
			$('#office').on('focus',function(){ $(this).autocomplete('search', ''); });
Abu Ghufran - Dev Team
Grid 4 PHP Framework
Abu Ghufran Staff replied 3 years ago

You can use same setting for
$grid[“edit_options”][“afterShowForm”] = “…”;

And finally $g->set_options($grid);

pcattani answered 3 years ago

That works beautifully, thanks!


I just had to do one tweek and change 100ms to 1000ms because I was getting a JS error:


Uncaught Error: cannot call methods on autocomplete prior to initialization; attempted to call method ‘search’.


Now all potential select values are shown whenever someone clicks inside the field.

pcattani answered 3 years ago

Update for people who are using this autocomplete (combobox-like solution):


I was having an issue with a field which refused to show all values onFocus.  The solution was to change the search parameter to include a space:


$(‘#myfield’).on(‘focus’,function(){ $(this).autocomplete(‘search’, ‘ ‘); });


This works, although for some reason, when I applied this to first load without focus, the values actually popped up just by scrolling the form.  So I removed this part:


// for first load without focus

$(‘#myfield’).autocomplete(‘search’, ”);


And the results seem to be operationally the same.  There was no noticable difference in drop-down time.



pcattani answered 3 years ago

Ignore all of that.  I had my: $col[“editoptions”][“onfocus”]  configured wrong.

Juan P answered 2 years ago

What is the correct configuration that works for you?

Your Answer

12 + 20 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.

How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?