Hi,

I'm currently using drupal_get_form() to create a node form programmatically.

In my hook_form_alter(), I've made it so that all elements (except the submit button) are hidden, using $form[element]['#access']. I'm populating the values programmatically, so that the user only sees the 'submit' button.

Ajax.module works fine in this respect. However, I'm also using Ajax Views Refresh, and this module won't work properly when I perform the above. I believe this is due to the fact that the 'complete' hook is not called, which is why this is an issue for Ajax.module and not Views Refresh. It doesn't seem to be called when there is a lack of <input>s, maybe?

As a workaround for myself, I can hide the element using CSS.

Unfortunately I'm not very good with JS, so I can't help too much.

Thanks!

Comments

PixelClever’s picture

Title: 'Complete' Hook is not called when all FAPI elements are hidden » 'Complete' Hook is not called at all
Priority: Normal » Critical

I ran some test and I am finding that the complete hook doesn't get called even when hidden fields are not involved. For some reason it hits an infinite loop at scroll find and doesn't ever reach complete.

rickmanelius’s picture

I have the same issue. If I use other flags (e.g. init, submit, etc), I get it working perfectly... meaning I can call an alert and see it display a message. But with 'complete', I can't get anything to work.

rickmanelius’s picture

Additional information...

If you add to your plugin the following line

Drupal.Ajax.plugins.my_pluging = function(hook, args) {
alert(hook);
}

You will see the form in every stage. The following hooks appear...

init
submit
message
scrollfind
scrollfind
scrollfind
scrollfind
scrollfind

Essentially as #1 mentions, it's getting into some infinite loop and never getting to the complete hook.

rickmanelius’s picture

Hey All,

It turns out that you can get a workaround... instead of using "complete", use "message". For me it worked because I just wanted to make sure the submission was complete before updating part of the DOM. And since "message" occurs after, it's all good.

I tried for about an hour to debug/turn off the scrollfind hook... but to no avail. I personally don't need it and it goes into a loop... so I'd rather see it go myself.

rickmanelius’s picture

Does anyone here have any pointers on how to fix this otherwise? I'll gladly spend an hour... but simply trying to comment out certain portions of the code led me nowhere.

I can't seem to figure out why it's hitting that infinite loop with the scroll hook.

rickmanelius’s picture

So the problem with "complete" not being called is it requires an '#action' field for the form. Note line 317 of the ajax.js file

// If no redirect, then simply show messages

So put bluntly, a form must have an action for the complete hook to be called. This kinda sucks, because then one essentially has to add hook_ajax_types to get it into ajax_ui and then select the disable redirect option for the particular form. It also has the weird behavior that the form resets to it's original value right after completion.

I'm not complaining... I just never knew it would get this deep when I decided to go with this module!

I'll report in as updates become available.

rickmanelius’s picture

After looking at the dev version... "complete" has been renamed as "redirect", which makes sense now.

So it's simply the documentation being a little out of sync with the stable versus dev versions. Just a warning for others reading this...

rickmanelius’s picture

More words of wisdom... because the args is different for each hook, make sure you figure out exactly which parameters are in that hook before trying to reference them. When I was trying to find the form id after I switched which hook I was using, the function stopped working.