Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
By lucadeluchis on
Hello!
I've got a content type and I'm trying to connect a couple of fields to related taxonomy fields
The field in content type is a term reference with autocomplete called "field_descrizione_01" (related to taxonomy term's name) with an empty field "field_udm"
The taxonomy terms has field "field_udm_ti"
I've seen a post about something similar and I've tried to modify the code, but it's not working.
/**
* Implements hook_field_widget_form_alter().
*/
function collegamento_field_widget_form_alter(&$element, &$form_state, $context) {
if(isset($element['#field_name']) && $element['#field_name'] == 'field_descrizione_01') {
$element['#ajax'] = array(
'callback' => 'collegamento_auto_fill_callback',
);
}
}
function collegamento_auto_fill_callback(&$form, &$form_state) {
$commands = array();
if(isset($form_state['values']['field_descrizione_01'])) {
// get selected item/node from dropdown list
$nid = $form_state['values']['field_descrizione_01']['und'][0]['nid'];
// load node by nid
$node = node_load($nid);
if($node) {
if(isset($node->field_udm_ti['und'])) {
// fill text field
$commands[] = ajax_command_invoke('#edit-field-udm', 'val', array($node->field_udm_ti['und'][0]['value']));
}
}
}
return array('#type' => 'ajax', '#commands' => $commands);
}
Somebody told me to modify it using load a taxonomy term using taxonomy_term_load.
So iv'e tried changing $node = node_load($nid); in $node = taxonomy_term_load($nid);
But it wasn't working
Comments
I've changed and try to use
I've changed and try to use content type instead of taxonomy, but I've got other problems.
I'm using field collection module (name: man ordinaria), and now it's not working for this.
I've modified
#edit-field-udm
with this:#edit-field-man-ordinaria-und-0-field-udm-und-0-value
But still have nothing workig...someone can know what's the problem?