Hello, I have a table with 10000+ record (id, name). I like to make a field like autocomplete but I like to get back the id not the name. Now I make this: function autocomplete_athlete($string = '') { $matches = array(); if ($string) { $result = db_query_range("SELECT a.item_id, a.name FROM names as a WHERE a.name LIKE LOWER('%s%%')", $string, 0, 10); while ($user = db_fetch_object($result)) { $matches[$user->name. '#'.$user->item_id] = $user->name; } } drupal_json($matches); } And on the onblur javascript event I change the field to the id with a split. But I think this is not a very nice solution. How can I make it to nice? Ámon Tamás Sitefejlesztő és programozó -- 5NET Informatikai Kft. 1062 Budapest, Aradi utca 38. A 3/11 telefon: (1) 461-0205 | fax: (1) 461-0206 e-mail: amont@5net.hu | web: http://www.5net.hu
Amon, Check out the form_set_value() function. It's intended (I think) to be called from your field's validate function. There you can convert a list of names into ids. Also look into your field's _value() callback. There, you can convert a default value (list of ids) into a string. -Dave On Thu, 18 Sep 2008 10:10:22 +0200, "Ámon Tamás" <amont@5net.hu> said:
Hello,
I have a table with 10000+ record (id, name). I like to make a field like autocomplete but I like to get back the id not the name. Now I make this:
participants (2)
-
David Cohen -
Ámon Tamás