I have a child window that is not closing when I use an AHAH callback on another element in the form.

Running the latest dev version and Drupal 6.19

This is easy to reproduce using a dummy submit button on the example modules:

<?php
/**
 * Generate the form for the child window.
 */
function modalframe_example_simple_form(&$form_state) {
  $form = array();

  // Send the Modal Frame javascript for child windows to the page.
  modalframe_child_js();

  $page_arguments = func_get_args();
  array_shift($page_arguments);

  $form['markup'] = array(
    '#type' => 'markup',
    '#value' => '<pre>'. t('Page arguments') .': '. check_plain(var_export($page_arguments, TRUE)) .'</pre>',
  );
  $form['is_after_12'] = array(
    '#type' => 'radios',
    '#title' => t('What time is it?'),
    '#options' => array(t('Before 12:00 AM'), t('After 12:00 AM')),
    '#default_value' => 0,
  );
  $form['break-me'] = array(
    '#type'  =>  'submit',
    '#value'  =>  t('Break me'),
    '#submit' => array('nothing_here'),
    '#ahah' => array(
      'path' => 'common/ahah/add][options', // . implode('][', $element['#array_parents']),
      'wrapper' => 'imagefield-editor-action-settings',
      'method' => 'replace',
      'effect' => 'fade',
      'event' => 'click',
    ),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
  );
  return $form;
}
?>

Sorry, I haven't time to look at this myself.

Comments

markus_petrux’s picture

Category: bug » support
Status: Active » Fixed

AHAH does not use the same flow of execution of the form, so you should find a way to process the result of the AHAH response and close the modal frame when you exactly need.

Probably, you need to use the close() method of the modal frame api (see parent.js) from the callback of your AHAH code client-side.

However, an AHAH button looks to me more appropriate for a button that's not designed to close a form. See for example the "Add more values" buttons in CCK fields that accept multiple values. That works perfectly well inside modal frames.

alan d.’s picture

Category: support » bug
Status: Fixed » Active

Sorry for switching back, but I think you have misunderstood what I was referring to. It wasn't the submit action from the AHAH button, but it is that the standard button from the example doesn't triggers the close action anymore.

The only difference is the presence of the AHAH processed element. Just try the above code (it is just the additional submit button element) and decide if you think that this is a bug.

From memory, the magic for CCK is added very late in the FAPI workflow (post render callbacks I think), and not at the very start like in the example above. This has considerable implications on how modules interact.

Cheers

markus_petrux’s picture

Category: bug » support
Status: Active » Fixed

Re: "the magic for CCK is added very late in the FAPI workflow (post render callbacks I think), and not at the very start like in the example above."

Nope. CCK adds its own stuff (including AHAH buttons for multiple value fields) using hook_form_alter() against node forms. Note that hook_form_alter() is invoked when the form is built, so there's no difference. It's a regular Drupal AHAH implementation. And that works perfectly well with Modal Frame API. However, the modal frame is not closed when an "Add more values" button is clicked. It shouldn't.

If you want to close the modal frame as a result to process an AHAH request, then you have to explicitly code that behavior yourself in the client-side code that processes the response of the AHAH request. You should also provide a method to process that button when javascript is not enabled.

BTW, you have just posted the code where you build the form, but you're not showing the code where you do something to close the modal frame, which is something that does not happen automagically. You should invoke the proper API in the proper way to close the modal frame. You can do it client-side (from the parent or child window), and you can do it server-side. The method to use depends on your particular use case.

alan d.’s picture

Category: support » bug
Status: Fixed » Active

FORGET THE AHAH BUTTON ITSELF

Sorry for shouting but the button has nothing to do with this issue! Apart from being the trigger to the bug!

The presence of this STOPS THE STANDARD SUBMIT BUTTON FROM CLOSING THE WINDOW

Steps to replicate.

1) Install and Enable the examples module
2) Modify this slightly to include the above FAPI button AHAH enabled element (this button has no other role)
3) Run the demo
4) Click the STANDARD submit button and see what happens..... The close mechanism is broken!

It takes all of 2 minutes to test if you have an install with the module running.

Cheers

markus_petrux’s picture

Status: Active » Postponed (maintainer needs more info)

Ok, let's keep this open. However, it seems to me the problem exists in the way the example module has been modified. You should debug this to see what's going on. I do not have the time for that. Sorry.

How could it be that other AHAH implementations work, but yours as above does not? where's the difference? hmm...

xtfer’s picture

Im seeing this on a custom modal loading a normal filefield widget via cck hooks. On submission, the window does not close. I have 10 other modals all working perfectly, but this one does not, and the AHAH filefield widget is the only difference.

Any suggestions?

xtfer’s picture

Status: Postponed (maintainer needs more info) » Active
webadpro’s picture

I'm actually having the same issue with filefield and Node reference(multuple=true) fields.

Has anyone fixed this issue?

webadpro’s picture

Actually, I'm having the same issue with CCK field that has unlimited number of values and filefield.

markus_petrux’s picture

Status: Active » Postponed (maintainer needs more info)

I'm unable to reproduce. It works here with any kind of CCK field I tested. There may be another module in game that breaks the expected behavior.

Hunabku’s picture

Version: 6.x-1.x-dev » 6.x-1.7

Me too - mine is happening when i include a CCK nodereference field and a filefield image - then the child window doesn't close. I tried taking out modules, as markus suggests - but to no avail. Also, strangely enough, the problem occurs when I have NO CCK fields - then when i add the first one (a nodereference) the problem goes away.

It might be useful to know that i'm running jQuery Update 6.x-2.0-alpha1 with jQuery 1.7.3 and i'm attaching a submit handler in my child form_alter as follows:
$form['buttons']['submit']['#submit'][] = 'your_modalframe_form_submit'.

I have to squash this bug so I'll try any suggestions at this point - including adding custom jQuery to force the window to close - but i'm not sure how to do that . . .

apaqui’s picture

I had this problem when i created a menu entry that calls directly to drupal_get_forms

AHAH rebuild the form and lose or dont works the function modalframe_child_js() then modalframe can't close.

SOLVE:

Create a menu entry that calls to your function

function my_function_callback($form_name) {
modalframe_child_js();
return drupal_get_form($form_name);
}

Hunabku’s picture

Not sure why this works, but after i moved modalframe_child_js(); to the afterbuild of my form alter all works correctly now.

dsnopek’s picture

Issue summary: View changes
Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

There was a fix for a similar problem committed to Automodal: #1698358: When form in child uses AHAH, automodalClose doesn't work (patch included!). Can you try opening the modal with automodal and see if that works? If so, you may have to copy the approach used in that commit to your module. For now marking as "closed (cannot reproduce)".