Hi
I have a form which uses multistep module and in the last step, there is flexi-field with multiple values, let me describe more clearly.
Multistep module with flexi field and modalframe module.
1) STEP 1 = No flexi field (modal window gets closed)
2) STEP 2 = No flexi field (modal window gets closed)
3) STEP 3 = Flexi-field with multiple values (modal window is not getting closed)
4) STEP 4 = No flexi field (modal window gets closed)
5) STEP 5 = Flexi-field with multiple values (modal window is not getting closed)
I called the custom submit function defined in the modalframe's example module modalframe_close_dialog in defferent steps one by one.
So, what exactly is the problem here I could able solve it.
Comments
Comment #1
vivek.saurabh commentedHi All,
BTW, I resolved the problem.
So, here comes the deadly combination of Flexifiled, Multistep and Modal-Frame.
Problem Number 1
Modal-Frame is not getting closed when you reach the last-step of Multi-step module.
Solution
Write a custom submit handler for the last step of the multi-step module in your form alter module(your custom module).
Add modalframe_child_js() and
modalframe_close_dialog(array(
'message' => (t(' created!')),
));
Reason The multi step module is redirecting when you click the DONE button and because of that the modalframe_child_js() is not getting called.
Problem Number 2
When you click the previous button, the modal frame's child.js file is not getting loaded, similar things happen during validation also.
Solution
create a custom submit handler $form['buttons']['previous']['#submit'][] = 'your_module_submit_handler' and add modalframe_child_js().
Problem 3
If you want to create the node in a normal drupal flow i.e without modal frame, the child.js file is still getting loaded which distort the theming.
Solution
Here comes the power of menu system.
// Send the Modal Frame javascript for parent windows to the page.
modalframe_parent_js();
// Add the client-side behaviors for the examples.
drupal_add_js(drupal_get_path('module', 'modalframe_example') .'/modalframe_example.js');
$items = array(
modalframe_example_get_item(t('Drupal'), 'node/add/abc/is_modal', '800,550'),
); );
$form['add-activity'] = array(
'#type' => 'item',
'#value' => '
' . theme('item_list', tems),
);
The path mentioned in the $items is having is_modal which is add in order to get the if condition for modalframe_child_js() API working only for modal frame.
In all your custom submit handler i.e $form['buttons']['previous'][''#submit] and $form['buttons']['next'][''#submit] add
if(arg(3) == 'is_modal' || arg(4) == 'is_modal'){
$form_state['redirect'][0] .= '/is_modal';
}
I am not going to explain it in full details, the only reason you need the above mentioned code to add the is_modal in the path created by the multistep module i.e /node/123/xyz/edit/2/is_modal.
Multi-step module saves the node on every step and when you click the NEXT it takes you to the edit node page.
Forgot to add one more thing add the following code in your hook_form_alter.
if(arg(3) == 'is_modal' || arg(4) == 'is_modal') {
$form['buttons']['next']['#submit'][] = 'modal_multi_correction';
$form['buttons']['previous']['#submit'][] = 'modal_multi_previous';
modalframe_child_js();
}