My question is about textfield autocomplete. I have this code:
function my_module_menu(){ $items['my_module/textfield_autocomplete'] = array( 'page callback' => 'my_module_textfield_autocomplete', 'file' => '.my_modulemy_module.inc', 'type' => MENU_CALLBACK, 'access arguments' => array('access example autocomplete'), ); return $items; }
In my_module.module
:
$form['fieldset7-wrapper']['prop'][$i] = array( '#type' => 'textfield', '#title' => t('Nombre de propietario'), // The autocomplete path is provided in hook_menu in ajax_example.module. '#autocomplete_path' => 'my_module/textfield_autocomplete' );
In my_module.inc
:
function inmoges_ofertas_propietario_autocomplete($string) { $matches = array(); // Some fantasy DB table which holds clientes foreach ($return as $row) { $value = check_plain($row->name).' '.check_plain($row->surname1).' '.check_plain($row->surname2); //$value = $row->name.' '.$row->surname1.' '.$row->surname2; $matches[$value] = $value; } // return for JS drupal_json_output($matches); }
This works perfect. But I want that json return callback {nid; name}
instead of {name,name}
, and also show the name in textfield, but I can save nid
in my form.
If I change to this my function ajax
$matches[$row->nid] = $value;
The previous sentence returns {nid, name}
, but if I choose one value of the list name, in the textfield is shown the nid
value, not the name
value.
Any suggestions?