Active
Project:
Subform
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
22 May 2012 at 11:37 UTC
Updated:
22 May 2012 at 11:42 UTC
Is there any way tho rebuild the parent form after submit a button in subform via ajax ? I try adding the submit callback "subform_submit_all" to the submit button (in subform) but it not work.
I need this feature when the subform need arguments that are provided by parent form
Here is my code:
/**
* Wrapper form.
*/
function mymodule_wrapperform($form, $form_state) {
$form['parent_name'] = array(
'#type' => 'textfield',
'#title' => t('Parent name'),
);
$arg = isset($form_state['values']['parent_name']) ? $form_state['values']['parent_name'] : time();
$form['subform'] = array(
'#type' => 'subform',
'#subform_id' => 'mymodule_subform',
'#subform_arguments' => array($arg), // this arg is provice by parent form
'#required' => FALSE,
);
return $form;
}
/**
* Subform
*/
function mymodule_subform($form, $form_state, $arg) {
$form['subform_apply'] = array(
'#type' => 'submit',
'#value' => t('Apply (button in subform)'),
'#submit'=>array('subform_submit_all','mymodule_subform_apply_submit'),
'#ajax' => array(
'callback' => 'mymodule_ajax_callback',
'wrapper' => $select_id,
),
);
$form['subform_name'] = array(
'#type' => 'textfield',
'#title' => 'Subform name',
'#default_value' => $arg, // this arg is provice by parent form
'#prefix' => '<div id="subform-div">',
'#suffix' => '</div>',
);
return $form;
}
/**
* Ajax callback
*/
function mymodule_ajax_callback($form, $form_state) {
return $form['subform_name'];
}
/**
* Submit callback
*
* @param type $form
* @param array $form_state
*/
function mymodule_subform_apply_submit($form, &$form_state)
{
$form_state['rebuild']=TRUE;
}
Thank all.