I don't think there's a reason for why we should limit the settings that can be passed via the #ajax element property.

Additionally, the 'effect' and 'speed' properties were using the same element property as source (bug).

Furthermore, the current code doesn't allow a custom 'path' to use a 'callback'. There's no reason why a contributed module shouldn't be able to fork system/ajax, if required, but still use callbacks.

Lastly, due to direct invocations of drupal_add_*() functions, the attached JavaScripts and settings cannot be cached.

Attached patch fixes all of that.

Comments

Status: Needs review » Needs work

The last submitted patch failed testing.

sun’s picture

Status: Needs work » Needs review
StatusFileSize
new4.4 KB

oh my... sorry, it's late here. :P

Status: Needs review » Needs work

The last submitted patch failed testing.

sun’s picture

Status: Needs work » Needs review
StatusFileSize
new9.76 KB

ok, I should really learn to copy + paste. :P

Also speeds up AJAX commands test.

Status: Needs review » Needs work

The last submitted patch failed testing.

sun’s picture

Status: Needs work » Needs review
StatusFileSize
new4.48 KB

ok, seems like the test didn't like that optimization for whatever reason. Reverted those changes.

Status: Needs review » Needs work

The last submitted patch failed testing.

sun’s picture

Title: ajax_process_form() is not extensible (and partially buggy) » #ajax is not extensible (and partially buggy)
Status: Needs work » Needs review

Interesting. This seems to reveal a bug elsewhere.

This patch changes

    drupal_add_js(array('ajax' => array($element['#id'] => $ajax_binding)), 'setting');

into

    $element['#attached']['js'][] = array(
      'type' => 'setting',
      'data' => array('ajax' => array($element['#id'] => $settings)),
    );

But Drupal.settings.ajax contains only the first element that is processed on a page.

sun’s picture

meh, silly me. This actually works like it should and is a major improvement on its own: The second AJAX settings were for a "Remove" button of a multiple value field widget in the form, which does not have a value yet, hence, the the settings were needlessly added before.

sun’s picture

Title: #ajax is not extensible (and partially buggy) » #ajax is not extensible and not cacheable, since ajax_render() doesn't support #attached

Clusterfuck. Better title.

When returning an AJAX command array, drupal_render() is not invoked, so #attached is not processed when submitting a form via AJAX. See http://api.drupal.org/api/function/ajax_deliver/7

At least, that's my current assumption. Not verified.

robloach’s picture

Hmm, interesting. Making a note to have a look as it seems pretty critical.

effulgentsia’s picture

sun’s picture

StatusFileSize
new8.84 KB

I'm a bit stuck in here. Not sure whether it's only the AJAX commands test that needs to be updated. If this patch works, then we only need to test manually whether AJAX still works with this patch ;)

Status: Needs review » Needs work

The last submitted patch failed testing.

sun’s picture

Status: Needs work » Needs review
StatusFileSize
new9.5 KB

This will make the remaining pass.

I mentioned manual testing above, because I'm not sure whether there is a full test of AJAX multiple value field operations: Add an item, add another item, remove an item, all on the same field. Afterwards, ideally try to add an item in a second field.

The question is whether - after adding an item - the attaching behaviors environment will contain the AJAX settings for the remove button. And after removing, whether it will still contain the settings for the add button 8)

Not even sure whether this can be tested in an automated way, because this requires a JavaScript environment.

sun’s picture

Title: #ajax is not extensible and not cacheable, since ajax_render() doesn't support #attached » #ajax is not extensible (and partially buggy)
StatusFileSize
new4.63 KB

And of course, it doesn't work. Let's leave that to a separate issue, because I fear it will require quite some API changes.

Instead, I've stuffed a @todo in there that explains the situation.

Anyone up for RTBC'ing this patch?

sun’s picture

effulgentsia’s picture

Status: Needs review » Reviewed & tested by the community

Makes sense and nice clean up. I want to investigate the @todo that's in there, but not today, and in any case, whatever the problem is, it's in HEAD, and this patch doesn't change it, so the rest of the nice cleanup that's here shouldn't be held up.

robloach’s picture

Status: Reviewed & tested by the community » Needs review

I want to RTBC it, but would like to talk with tha_sun on IRC first.

robloach’s picture

Status: Needs review » Reviewed & tested by the community

Whoops, effulgentsia beat me to it! I'm all thumbs up if he backs it! :-)

Status: Reviewed & tested by the community » Needs review

Re-test of drupal.ajax-process-form.17.patch from comment #17 was requested by webchick.

effulgentsia’s picture

Status: Needs review » Reviewed & tested by the community

as per #21

damien tournoud’s picture

Status: Reviewed & tested by the community » Needs work

-1 for @todo in our code. It's not like we could plan to do something later at this point. We need that to work, fully and completely.

sun’s picture

Status: Needs work » Reviewed & tested by the community
webchick’s picture

Status: Reviewed & tested by the community » Needs work

Sorry, but I agree with Damien. The time for "Oh, we'll fix that in a follow-up patch" is behind us now.

sun’s picture

Status: Needs work » Needs review

err, guys, these are completely separate issues. Please define scope-creep.

This patch fixes one bug. The other issue will need to fix the other bug.

sun’s picture

Status: Needs review » Reviewed & tested by the community

Really, #656782: ajax_process_form() results in settings being returned for elements that aren't re-rendered as part of the AJAX request contains a very clear and concise description of the second bug. Did you actually read it?

It would be insane to intermix both issues. While this one is a regular and quite simple bug fix, the other issue should probably bumped to critical, since it questions our entire element processing, caching, and rendering, and may require larger changes to the AJAX framework and/or form processing and/or element rendering.

webchick’s picture

I did read it. It says that this patch introduces a critical bug, by breaking AJAX with cached elements, which needs to be cleaned up afterwards. Or are you saying that that bug exists regardless of this patch?

sun’s picture

sorry, if that didn't come through - yes, this bug exists in HEAD already. It was revealed by this patch. That's why this patch does not convert all drupal_add_js() lines into ['#attached']['js'] properties, because the settings cannot be converted currently. Figuring out why that is and how to solve it, is the focus of the other issue.

I will post a patch containing that particular change (== outlined in #8 above) to the other issue. And this one-liner will break, because something goes wrong in our form or element processing/caching/rendering.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Oops. This fell off my radar.

Ok, cool. I assume our AJAX tests would scream if anything were too odd with this patch, so committed to HEAD.

Status: Fixed » Closed (fixed)

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