Probleme de champ ahah imbriqués

Catégories:

bonjour,

J’ai créé un module de type node qui affiche un formulaire dans ce formulaire il y a des textfield qui ont des champs ‘#ahah’ pour verifier le contenu et il y a aussi un boutton qui ajoute via ahah un nouveau champ identique au precedent mais l’evenement ahah ne fonctionne pas sur ce dernier

Pouvez vous m’aidez ?

Voici mon code :
hook_form appelle cette fonction :

<?php
function histoire_add_field($delta,$module,$value='')
{
 
$id = 'fields-'.$module;
 
$form = array(
   
'#tree' => TRUE,
  );

  $form['ids'] = array(
   
'#type' => 'textfield',
   
'#title' => t('ID'),
   
'#default_value' => 0,  
   
'#prefix' => '<div  class="id-field">',
   
'#suffix' => '</div>',
   
'#disabled' =>true,
   
'#parents' => array('fields-'.$module, $delta,'ids'),
  );
 
$form['nom'] = array(
   
'#type' => 'textfield',
   
'#title' => t($module.' @n', array('@n' => ($delta + 1))),
   
'#default_value' => $value,
   
'#prefix' => '<div class="nom-field">',
   
'#suffix' => '</div><div  id="check-'.$id.'-'.$delta.'" ></div>',
   
'#parents' => array('fields-'.$module, $delta,'nom'),
   
'#autocomplete_path' => 'histoire/autocomplete/'.$module,
   
'#ahah' => array(
     
'path' => 'histoire/check/'.$module.'/'.$delta,
     
'wrapper' => 'check-'.$module.'-'.$delta,
     
'method' => 'replace',
     
'effect' => 'fade',
    ),
  );
  return
$form;
}
?>

avec hook_menu cette fonction est appellé :

<?php
function histoire_ahah() {
 
$module = arg(2);
 
$type = arg(3);
 
$plural = $type.'s';
 
$id = $plural.'-'.$module;
 
$delta = count($_POST[$id]);

  //Dans ce cas appelle histoire_add_field
 
$form_element = histoire_add($delta,$module,'',$type);
 
//print_r($form_element);
 
drupal_alter('form', $form_element, array(), 'histoire_ahah');

  // Build the new form.
 
$form_state = array('submitted' => FALSE);
 
$form_build_id = $_POST['form_build_id'];
 
// Add the new element to the stored form. Without adding the element to the
  // form, Drupal is not aware of this new elements existence and will not
  // process it. We retreive the cached form, add the element, and resave.
 
$form = form_get_cache($form_build_id, $form_state);
 
$form[$module][$id][$delta] = $form_element;
 
form_set_cache($form_build_id, $form, $form_state);
 
$form += array(
   
'#post' => $_POST,
   
'#programmed' => FALSE,
  );

  // Rebuild the form.
 
$form = form_builder('histoire_node_form', $form, $form_state);

  // Render the new output.
 
$ahah_form = $form[$module][$id];

  unset($ahah_form['#prefix'], $ahah_form['#suffix']); // Prevent duplicate wrappers.

  $ahah_form[$delta]['#attributes']['class'] = empty($ahah_form[$delta]['#attributes']['class']) ? 'ahah-new-content' : $ahah_form[$delta]['#attributes']['class'] .' ahah-new-content';  
 
$ahah_form[$delta]['ids']['#value'] = 0;

  $output = theme('status_messages') . drupal_render($ahah_form);

  drupal_json(array('status' => TRUE, 'data' => $output));
}
?>

Thanks

Syndiquer le contenu