Hello, I'm using an autofill code founded on another post, when I'm usinng it in conditional fields (called man ordinaria) with multiple entries it's not working.

I've modified #edit-field-art-und-0-value with this: #edit-field-man-ordinaria-und-0-field-art-und-0-value

But is not working.

Somebody knows how to fix it?
Thank you!


<?php
// $Id$

/**
* Implements hook_field_widget_form_alter().
*/
function MODULE_NAME_field_widget_form_alter(&$element, &$form_state, $context) {

  if(isset($element['#field_name']) && $element['#field_name'] == 'field_points_of_contacts') {
    $element['#ajax'] = array(
      'callback' => 'MODULE_NAME_auto_fill_callback',
    );
  }
}


function MODULE_NAME_auto_fill_callback(&$form, &$form_state) {

  $commands = array();

  if(isset($form_state['values']['field_points_of_contacts'])) {
    // get selected item/node from dropdown list
    $nid = $form_state['values']['field_points_of_contacts']['und'][0]['nid'];

    // load node by nid
    $node = node_load($nid);

    if($node) {

      if(isset($node->field_to_field_art['und'])) {
        $commands[] = ajax_command_invoke('#edit-field-man-ordinaria-und-0-field-art-und-0-value', 'val', array($node->field_to_field_art['und'][0]['value']));  
      }        



      
    }
  }

  return array('#type' => 'ajax', '#commands' => $commands);
} 

Comments

lucadeluchis’s picture

I found the problem, I needed to change this part $nid = $form_state['values']['field_points_of_contacts']['und'][0]['nid']; with the field of the content type.

$nid = $form_state['values'] ['field_man_ordinaria'][und][0]['field_points_of_contacts']['und'][0]['nid'];

But now I have a new prob connectet to the multiple entry.
When I put the first entry is ...['und'][0]['nid'] , when I add another terms the second becomes ...['und'][1]['nid'].

I don't know what to do about it.