Hi, I want to autocomplete the country name in the customer table when adding a new customer.
I have:
$col = array();
$col[“title”] = “Country”;
$col[“name”] = “country”;
$col[“formatter”] = “autocomplete”;
$col[“formatoptions”] = array(“sql”=>”SELECT country.Name as k, country.Name as v FROM dbo.Country”);
But when I start typing in the field then a message “500: Internal Server Error. Status: error” pops up.
I don’t want to have a select drop down but normal input field.
What am I doing wrong?
Thanks!
Check error detail in browser debugger (F12) -> Network tab -> Ajax response text.
It should display if there is error in your sql.
Let me know if not resolved and share screenshot as well.
Well, my sql query in $col[“formatoptions”] is reading from a different table; if I make the autocomplete query to the same table as the grid is using then it works as expected. By querying to a different table I get this as soon as I punch the first character:
I liked the idea that I could fetch data for the autocomplete form a different table (like to autocomplete country name instead of having a quite annoying select).
Check ajax response tab for exact error like this:
Hi Abu, It’s empty cause it an internal 500 error (and HTTP 500 error code). Strangely enough there is nothing on the php errors log file neither on the Apache log file. I don’t know where else to look.
I’m now starting to suspect that a php module is missing, do you know all the required modules?
Is your link online somewhere where i can see.
I can also check remotely if you setup https://remotedesktop.google.com/
Sorry Abu, I waitted for the remote connection and then had to go.
but, look at this code:
$g->table = "dbo.Customers";
$col = array();
$col["title"] = "Name";
$col["name"] = "name";
$cols[] = $col;
$col = array();
$col["title"] = "Country";
$col["name"] = "country";
$col["formatter"] = "autocomplete";
// this fails with HTTP error 500:
$col["formatoptions"] = array("sql"=>"SELECT name as k, name as v FROM dbo.Country");
// this works OK:
$col["formatoptions"] = array("sql"=>"SELECT DISTINCT country as k, country as v FROM dbo.Customers");
$cols[] = $col;
Both SQL querys work as they should in the SQL server.
Anyways I’m not planning to use more time on this. Thanks.
Hello,
Apolgies for the delay. Just to log solution, By default autocomplete searches on the field specified in $col[“name”], which is ‘country‘ in your case and searching works as it is part of your autocomplete query: SELECT DISTINCT country as k, country as v FROM dbo.Customers.
If you use different sql query or table which don’t have above field, you should also specify search_on field.
$col[“formatoptions”] = array(“sql”=>”SELECT name as k, name as v FROM dbo.Country”, “search_on”=>”name”);
Hope it helps.