PHP | Autocomplete data on multiple fields

the result I would need is very simple, given an autocomplete input, a city selected by the user I would like the latitude and longitude of the city chosen by the user to be completed in two hidden fields.

Now my code accesses an external wordpress table where, it allows the user to be able to select only the name of the city

table: places

table fields:

name lat lon 


roma 41.8933203 12.4829321 


<script>     /*ACCEDI ALLA LATITUDINE E LONGITUDINE DA TABELLA ESTERENA*/      var places_geo = <?php          global $  wpdb;          $  accedi_tabella = $  wpdb->get_results( "SELECT * FROM place" );          $  nomi_places = [];         foreach( $  accedi_tabella as $  place ){             $  nomi_places[] = $  place->name;         }         echo json_encode( $  nomi_places );         ?>;     places_geo.length||(places_geo=[]);     $  ('#form-geo').mdbAutocomplete({         data: places_geo     });      $  ('#form-geo').mdbAutocomplete({         data: places_geo     });  </script> 

input autocomplete:

<input type="search" id="form-geo" name="art"> 

as you can see from the script the value that will come out is only the name.

Now what I want

As said in the question, I would like that when the user clicks on: Rome, the results are output the two results of latitude and longitude in two hidden input fields

carry a jsfiddle, explaining what I want:

In the example typing google, at the time of selection, the selected result is displayed in the other two inputs. Well I would like two inputs to be displayed in the other two inputs (which currently do not exist) that show the fields: lat and lon

Cities/Countries Autocomplete query optimization

I have Cities and Countries tables, based on Geonames data. I’m trying to implement an autocomplete function, but so far it doesn’t work as I intend it to.

CREATE INDEX gin_pgtrm_testcity_big_index ON testcity_big USING gin ((name || ' ' || asciiname || ' ' || alternatenames) COLLATE pg_catalog."default"  gin_trgm_ops);  CREATE INDEX gin_pgtrm_tescountry_big_index ON testcountry_big USING gin ((name) COLLATE pg_catalog."default" gin_trgm_ops);  SELECT AS country, AS city,     city.population AS city_population,     city.fcode AS fscode,      similarity(coalesce(,'')                  || coalesce(,'')                  || coalesce(city.asciiname,'')      ,'%ribe dk%) AS rank  FROM testcountry_big country JOIN testcity_big city ON = country.iso_alpha2  WHERE similarity(coalesce(,'')                      || coalesce(,'')                      || coalesce(city.asciiname,'')      ,'%ribe dk%') > 0.15  AND fcode ~ '\yPPLC\y|\yPPLA\y|\yPPLA2\y|\yPPL\y|\yHMSD\y' ORDER BY rank DESC LIMIT 5; 

1. I cannot return country only. My current query retrieves cities only, for example for “New York United States” I get 4 different cities, but I’m not getting United States country, and I can’t understand how to make it work for all possible combinations: cities, countries , cities+countries.

2. This query performs too slow for an autocomplete function – around 0.5 seconds.

(a) should I add a Materialized View to help boost the performance?

(b) could it be so slow simply because I’m using a local machine (laptop) and the performance on a real server is expected to be better?

** I also tried working with tsvector here, but :

  1. unfortunately they only work for whole words and not substrings
  2. the performance seemed worse than with triagrams
  3. the similarity function using triagrams gives the ability for the users to be more “loose” with the queries, and get results even when they have a typo.

Having trouble with SPServices AutoComplete pulling from specific columns

I have 2 issues really. I have set this up successfully for some of my fields on my Nintex form. The autocomplete works perfectly.

Issue 1: I attempted to set this up on another field on another list. The field will not find anything when you start typing. I thought possibly I had the wrong crawled property, but I tried everything I could think of with no success.

Issue 2: I attempted to use a different column from the second list from Issue 1 to see if it was a column issue. I did get results, but they were not correct. In fact, I am unable to find ANYWHERE that the information in the auto-correct is displaying.

I can get the field to work if I connect it to the same columns as the other fields that are working. So it doesn’t appear to be a field or code issue. It seems that it either doesn’t like the list or the specific column.

I also tried to create a completely new list with column names I know are not being used anywhere else in our farm, but this didn’t work either.

I have no idea what’s going on. It’s quite puzzling. Below is my code.

NWF$  (document).ready(function() { //The source data for the autocomplete is the Journals list   //Store the journal titles in a array variable   var externalParties = []; NWF$  ().SPServices({     operation: "GetListItems",     async: false,     listName: "Vendor IDs",     CAMLViewFields: "<ViewFields><FieldRef Name='Vendor Name' /></ViewFields>", //the name needs to be changed accordingly        completefunc: function(xData, Status) {         NWF$  (xData.responseXML).SPFilterNode("z:row").each(function() {             externalParties.push(NWF$  (this).attr("ows_VendorName").substring(8));         });     } }); //journalinput is added on the control in the NF   NWF$  ("#" + journalinput4).autocomplete({     source: externalParties }); }); 

Spservices autocomplete with many columns

Could somebody advise how can I make autocomplete for multiple columns, currently I’m using it for one column:

$  ().SPServices.SPAutocomplete({     sourceList: "My list",     sourceColumn: "Email",     columnName: "user1",     ignoreCase: true,     numChars: 3,     slideDownSpeed: 1000,     debug: true }); 

Can I do something like this:

... columnName: "user1", "user2", "user3"... etc. ... 


My form and JavaScript looks like this:

<div class="tr">   <div class="td">     <input title="user1" data-bind="textInput: user1Email, valueUpdate:'blur'" />   </div> </div> <div class="tr">   <div class="td">     <input title="user2" data-bind="textInput: user2Email, valueUpdate:'blur'" />   </div> </div>  <script type="text/javascript"> $  (document).ready(function () {     $  (["user1", "user2", "user3"]).each(function () {         $  ().SPServices.SPAutocomplete({             sourceList: "User List",             sourceColumn: "Email",             columnName: this,             ignoreCase: true,             numChars: 3,             slideDownSpeed: 1000,             debug: true         });     }) }); </script> 

cd autocomplete displays tons of info

I use a lot of folders to organize my classes in school and often I simply have a folder inside another one all by itself as I know in the future I’ll add more. For example Folder0 -> Folder1 by itself -> multiples files.

My question is when I do cdthen try to autocomplete with Tab in my shells with nothing behind it, it shows me a lot more than expected and as such doesn’t directly work, as shown in this screenshot.

enter image description here

Is this normal ? If yes how can I disable it so I can autocomplete directly into my unique folder ?

Thanks already

Select from a dropdown (or autocomplete) or add new item in same create / edit view

I’ve always run into this conundrum: How to give the user a long list of options and allowing them to populate their own if it doesn’t exist.

I usually handle this interface by giving an autocomplete list for a textbox, then if they select one, mark a variable that it’s existing (kind of like the “Tags” box on here). If it isn’t from the list, then I add new. I’ve also had radio buttons auto-tick or be user-ticked based on “Add”, “Edit”, and “Select” options.

I’ve never really loved the above approach, and I was wondering if there was a cleaner better approach to giving the user an option to use an existing or add a new value.

autocomplete con archivo externo json

tengo este código y funciona, solo que deseo hacer que la fuente de las ciudades las obtenga desde un archivo Json externo, por que deseo colocar muchas ciudades. Pero no logro crearlo.

$  ( function() {     var availableTags = [       "Xalapa, Ver. Mx",       "Boca del Rio, Ver. Mx",       "Aguascalientes, Aguascalientes, México",       "La Mascota, Aguascalientes, México",       "Matamoros [Congregación], Aguascalientes, México"     ];     $  ( "#ciudades" ).autocomplete({       source: (request, response) => {         // Filtramos el arreglo de tags         let result = availableTags.filter(tag => {           // Implementamos nuestro filtro personalizado           return tag.toLowerCase().startsWith(request.term.toLowerCase());         });         // Llamamos a `response` con los datos filtrados         response(result);       },       change: function(e, ui) {         if (!ui.item) {           $  (this).val("");         }       },         response: function(e, ui) {             if (ui.content.length == 0)              {                 $  (this).val("");             }         }         })           .on("keydown", function(e)            {             if (e.keyCode == 27)              {               $  (this).val("");             }           })   } ); 

sé que en el source debe llevar el nombre del archivo JSON, pero este codigo me lo pasó una persona aquí en este foro y permite listar las ciudades por inicial ademas de que valida y no permite seleccionar una ciudad que no exista en la lista.

Jquery autocomplete. undefined method

Estoy implementando Jquery Autocomplete. Pero me arroja el siguiente error:

undefined method `product_pro_nombre’ for #Did you mean? product_id_change

mi vista _order_detail_fields.html.erb

    ...     <%= f.hidden_field :product_id, id: 'temp_id', disabled: "disabled" %>     <%= f.autocomplete_field :product_pro_nombre, autocomplete_product_pro_nombre_order_details_path, 'data-showNoMatches' => false, class: "form-control producto", :id_element => '#temp_id', onchange: "setValue(event)" %>     <%= f.hidden_field :product_id, class:"product" %>     ... 

Funciona bien el autocomplete si en lugar de :product_pro_nombre lo dejo como :product_id. Pero al momento de recuperar esta vista para hacer un UPDATE, en lugar del nombre del producto me muestra el ID. Entiendo el porque del error, ya que el product_id es una llave foranea de OrderDetail. Pero no encuentro la forma de recuperar el nombre.

Esta es la documentación que estoy siguiendo