Hello,

I would like to know how to retrieve informations from the parent page in javascript.

I have a custom cck component who display a button to open a modal popup.
In this popup I want to display a sub-form with complex jquery / ajax behaviors.

First I load a "mymodule_modal.js" file with a lot of informations into the Drupal.settings, example :

$settings = array( 'mymodule_modal' => array( 'options' => 2, 'useCancel' => 1, 'actions' => array( 'action1' => 1, 'action2' => 0, 'action3' => 'default' )));
drupal_add_js( $settings, 'setting' );

Theses settings are available from Drupal.settings.mymodule_modal when I'm in the "mymodule_modal.js".

Now the modal popup call a callback with drupal_get_form. the function is like this :

function mymodule_get_modal_form( &$form_state, $fieldname ) {
	
  $form = array();
  
  modalframe_child_js();
  
  drupal_add_js( drupal_get_path( "module", "mymodule" ) . "/mymodule.js" );

  $form['container'] = array(
    '#type' => 'markup',
    '#value' => '<div id="'. $fieldname .'_div_container" class="div_container">
                    <ul id="'. $fieldname .'_ul_container" class="ul_container">
                    </ul>
                 </div><div class="clear-block"></div>',
  );

  $form['action_link'] = array(
    '#type' => 'markup',
    '#value' => '<input type="button" id="action_link" name="action_link" value="Action" />',
  );
  
  $form['cancel_link'] = array(
    '#type' => 'markup',
    '#value' => '<input type="button" id="cancel_link" name="cancel_link" value="Cancel" />',
  );
return $form;
}

Like you can see, I add a new js file to interact with my sub-form. But the problem is that I can't access to parent Drupal.settings.mymodule_modal informations (I think it's because the context)... So is there a possibility to retrieve js data from parent to child to access the values I want ?? I can't pass the values directly to the mymodule.js settings because I only access the variables I want in the build of the main form.

Thanks in advance for any suggestion :-)

Comments

titouille’s picture

Ok... I found a solution, but is it a correct way ??

I add all my settings in the customDialogOptions parameter and get if from child with :

settings = Drupal.modalFrameChild.parentModalFrame.options.customDialogOptions;

... It seems complicated, but it works.

dsnopek’s picture

Issue summary: View changes
Status: Active » Fixed

Yes, that is exactly the correct way to do that!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.