This is a continuation of #399982: Simplify and standardize returning an AHAH response. #544418: Integrate CTools AJAX framework with Drupal to extend (and replace) existing ahah framework has been committed, yay!
However, poll.module still has this:
function poll_choice_js($form, $form_state) {
...
return theme('status_messages') . drupal_render($choice_form);
}
However, the rendering of the form might produce additional status messages, so this probably should be changed to:
function poll_choice_js($form, $form_state) {
...
$output = drupal_render($choice_form);
return theme('status_messages') . $output;
}
But why make implementers of AJAX callbacks worry about that? Why not:
function poll_choice_js($form, $form_state) {
...
return drupal_render($choice_form);
}
And let ajax_form_callback() be responsible for the status messages?
I don't yet have a proposal for what the best way of handling it is. @quicksketch: do you have a recommendation?
Comments
Comment #1
sunsubscribing
Comment #2
rfaysubscribing
Comment #3
effulgentsia commentedI know we can do better than this patch, something more along the lines of full separation of messages all the way to the browser, like quicksketch proposes in http://drupal.org/node/399982#comment-1807684. But I'm not yet sufficiently up to speed on the new AJAX framework to create that patch, so here's a less ambitious solution. If we can't get the better one in on time, let's at least get this one in.
The thinking behind this patch is to make the simple use-case of a AJAX callback returning a string of html result in status messages automatically handled without the AJAX callback doing anything. However, to allow special AJAX callbacks the flexibility of NOT returning status messages, nothing is done if the AJAX callback returns an array of commands instead of an html string. For, example, if poll.module did not want status messages included with its result, it could change
to
A little complicated perhaps, but it moves the more complicated code needed to the exception (not wanting status messages) rather than having extra complication for the default situation (wanting status messages).
Comment #5
effulgentsia commentedSomething else that should be included with this issue is a fix to a bug introduced into HEAD from patch 72 of #367567: Use AJAX framework for "Add more" / load include file containing form / introduce $form_state['build_info']. When you click "add another item", if there's a validation error, that gets shown as a status message at the top of the new content. If you click "add another item" again, and if the same validation error occurs again, it gets duplicated. Or, if no validation error occurs the second time, the old one is still there. This is because the returned AJAX content (including the status messages) replace a previously defined "wrapper" div, but the status messages are outside of the *new* wrapper div, so a subsequent "add another item" doesn't replace the prior status messages. This can be easily tested by setting the "body" field of the "page" content type to "unlimited" number of values and having a maximum length of 1.
Comment #6
sun@effulgentsia: That particular issue is tackled in #370537: Allow suppress of form errors (hack to make "more" buttons work properly). See you over there :)
Comment #7
effulgentsia commentedReally? I thought that issue was just to make sure that *some* validation get bypassed (for example, validation of the node title field when you're adding another item of the body field). Are we saying that we plan on not validating *anything* when using the "add another item" button?
If that's the case, then what about other status messages (not validation errors)? Should those persist across multiple uses of "add another item", or get replaced each time?
Comment #8
effulgentsia commentedI'm having a hard time getting CVS to work for me right now. It's EXTREMELY slow (like taking 10 minutes per file to do a cvs update and not managing to do a cvs diff). I'm not sure if it's something funky with my room at Paris (here for DrupalCon), or if the server is crawling due to final stretch of code-freeze. @sun or @rfay, if you're having more luck with cvs right now, would you be willing to re-roll patch from comment #3? Do either/both of you agree that in the absence of some other solution being developed within the next few hours (what time and time zone is code-freeze?), this small patch is better than nothing?
Comment #9
rfayPer @effulgentsia's request, here is the patch from #3 re-rolled to fit the current HEAD.
@effulgentsia, the last rumor I heard was that we have until Dries's keynote to get it all together. Look forward to meeting you tomorrow.
Comment #10
effulgentsia commentedThis one solves the issue from comment #5. See comment #7 for why I believe this is important even if #370537: Allow suppress of form errors (hack to make "more" buttons work properly) lands. Note also that if a ajax callback wants to handle status messages differently, it can do so by returning an array of ajax commands instead of a string of html.
Comment #11
rfayWhy don't we fix the ajax_form_callback() while we're in here. It's using $html when really it should be named $commands, perhaps, or $content. Calling it $html masks the fact that it can be a list of commands.
It looks to me like this is an excellent cleanup that should go in.
The change to field.form.inc shows how this simplifies normal handling of status messages. Also, with this patch, the ordinary user doesn't necessarily even have to think about status messages, and they often don't anyway.
Comment #12
effulgentsia commentedThanks, @rfay, but I didn't follow closely all the work merlinofchaos and others were putting into the D7 ajax library, and I don't feel sufficiently empowered to override the decision on that variable name. I agree that it's an unclear name, and if someone wants to submit a separate patch for that, I'll be happy to +1 it.
For this patch, I reverted field.form.inc to return an array of commands instead of just the content, because I talked with yched, and he indicated a concern about not leaving an example of returning an array anywhere in core. Ajax.inc supports returning an array so that contrib modules, like views, can do fancier AJAX stuff than simply returning content.
Comment #13
rfayI think this is fine. It
Marking RTBC.
Comment #14
moshe weitzman commentedTHis looks sensible but I'm not really qualified to RTBC it. Code looks clear and proper.
Comment #15
rfaySetting back to RTBC, assuming @moshe & I cross-posted. If that's not the case, please set it back again.
Comment #16
sunIntroducing a new tag for feature freeze: API clean-up.
Comment #17
dries commentedI looked at this patch and it looks like an improvement -- with some bugfixing even. Would be nice to get @quicksketch to look at this too.
Comment #19
rfaySetting back to needs review and requesting retest.
Comment #20
rfaySetting back to RTBC, which was the status it belonged in. Still waiting for @quicksketch to chime in, though.
Comment #21
sun$commands need to be initialized here, so please revert the removal.
Instead of providing an example usage somewhere deeply hidden in core, we should move that example into the PHPDoc of ajax_command_replace() and just keep ajax_render(drupal_render($field_form)) here.
This review is powered by Dreditor.
Comment #22
webchickLooks like this needs some more work.
Comment #23
sunFixed the remaining issues.
Comment #24
dries commentedI re-reviewed sun's latest patch and it looks good so I committed it to CVS HEAD. Thanks all.
Too bad @quicksketch didn't provide input (re #17), but let's move forward. We can always revisit this when we get some extra feedback from quicksketch. :)
Let's update the documentation in the handbook and mark this as fixed.
Comment #25
rfayI'll plan to take care of the docs on this on a full AJAX docs sweep.
Comment #26
rfayDocumentation followup on this is moving to #610068: Document AJAX no-js and use-ajax. Many issues can be combined there.