Hi,
I have some trouble when i want to create an ahah button create by an other ahah button.
This will add correctly a new ligne. But when i click on the remove button create it's a submit form ($form['App_create_application']['ips'][$ip]['remove']) and not ahah.
Anyone have a idea ?
In admin.inc
'#prefix' => '<div id="wrapper-ip">',
'#suffix' => '</div>',
'ip_application' => application_ip_field($ip,$form),
);
$form['App_create_application']['addIp'] = array(
'#type' => 'textfield',
'#title' => t('New ip'),
'#description' => t('Liste d\'ip'),
'#required' => TRUE,
);
$form['App_create_application']['addIpSubmit'] = array(
'#type' => 'submit',
'#value' => t('Add IP'),
'#ahah' => array(
'path' => 'application/js/ip',
'wrapper' => 'wrapper-ip',
'method' => 'replace',
'effect' => 'fade'),
);
In myModule.module
'page callback' => 'application_js_ip',
'type' => MENU_CALLBACK,
'access arguments' => array('admin'),
'access' => user_access('admin'),
'file' => 'includes/admin.inc'
);
In admin.inc application_ip_field
if ((is_array($ipList) && count($ipList) > 0)){
foreach ($ipList as $ip){
$form['App_create_application']['ips'][$ip]['value'] = array( '#type' => 'item', '#value' => $ip);
$form['App_create_application']['ips'][$ip]['remove'] = array(
'#type' => 'submit',
'#value' => t('Remove'),
'#ahah' => array(
'event' => 'click',
'path' => 'application/js/ip',
'wrapper' => 'wrapper-ip',
'method' => 'replace',
'effect' => 'fade'),
);
}
}
return array(
'#type' => 'item',
'#value' => theme('ip_list', $form ),
);
}
In admin.inc function application_js_ip
// get the new IP
$ip=$_POST['addIp'];
// get unique form id
$form_build_id = $_POST['form_build_id'];
// set false form state
$form_state = array('submitted' => FALSE);
// get form from cache
$form = form_get_cache($form_build_id, $form_state);
// create element
$element=application_ip_field(array($ip),$form);
// add element inside the form (replace)
$form['wrapper-ip']['ip_application'] = $element;
// save form in cache
form_set_cache($form_build_id, $form, $form_state);
drupal_process_form($form_build_id, $form, $form_state);
// Rebuild form
$form = form_builder($_POST['form_id'], $form, $form_state);
// get new element
$element = $form['wrapper-ip']['ip_application'];
// get in HTML
$output = drupal_render($element);
// send HTML to client
drupal_json(array('status' => TRUE, 'data' => $output));
}









