[development] Another D7 AJAX/Form API change: drupal_rebuild_form()

Alex Bronstein alex at craftyspace.com
Wed Mar 31 21:00:02 UTC 2010


Since we're asking module maintainers to take the #D7CX pledge and port 
their modules to Drupal 7 now, so that they're ready when Drupal 7 is 
released and to help uncover any remaining not-yet-discovered critical 
bugs with Drupal 7 core, it makes sense for us to do our best to not 
break already ported modules. And even ahead of the beta releases, core 
developers have already been increasingly cautious and treating Drupal 
7's API as frozen. But sometimes, an API change is needed to resolve a 
critical issue. Randy has been suggesting that it would be awesome to 
have a process by which we can inform people about such changes, so that 
module maintainers who aren't monitoring Drupal 7 development on a daily 
basis can still know when they need to update the 7.x branch of their 
module in response to a Drupal 7 API change. I'm not aware of such a 
process already existing, so in the meantime, an email to this list 
seems appropriate.

With that in mind, this is a notification that the 3rd parameter to 
drupal_rebuild_form() 
(http://api.drupal.org/api/function/drupal_rebuild_form/7) has today 
changed from $form_build_id to $old_form. See 
http://drupal.org/node/671184 for the issue history. If your module 
implements a #ajax['path'] menu callback that calls 
drupal_rebuild_form(), you will need to update that line of code (see 
http://api.drupal.org/api/function/ajax_form_callback/7 for an example). 
#ajax['callback'] callbacks are unaffected.

- Alex.

Randy Fay wrote:
> Sorry - the new AJAX Forms page is at http://drupal.org/node/752056
>
> I'm hoping to expand upon that, and hoping that we can consolidate 
> some more of the D7 FAPI information as well.
>
> The Examples module now has a gracefully degrading AJAX dependent 
> dropdown as well, pointed to by http://drupal.org/node/752056.
>
> Thanks,
> -Randy
>
> On Fri, Mar 26, 2010 at 6:45 PM, Alex Bronstein <alex at craftyspace.com 
> <mailto:alex at craftyspace.com>> wrote:
>
>     Small clarification to this: #1 and #2 are true for when the
>     triggering element is not a submit button or image button (or more
>     precisely, when its #executes_submit_callback property isn't true,
>     which by default is only for submit buttons and image buttons). So
>     for example, when clicking a checkbox directly triggers AJAX. When
>     an AJAX-enabled submit or image button triggers an AJAX
>     submission, then by default, validation errors are reported and
>     either the button's #submit handlers or the FORM_ID_submit()
>     function do get executed as you're used to from D6 AHAH. In D7, a
>     button can set #submit and #limit_validation_errors to empty
>     arrays in order act the same as a non-button in this regard.
>
>     Hopefully, D7 FAPI and AJAX documentation will help make all this
>     clearer. Randy, can you please send the documentation link you
>     intended to send in the PS. The issue URL got pasted instead.
>
>     -Alex.
>
>     Randy Fay wrote:
>
>         If you're working with D7 AJAX Forms, you will be interested
>         in an API change this week.
>
>         With http://drupal.org/node/684846, the AJAX triggering was
>         refactored, and this has some effects on those of you using it:
>
>         The bottom line: The submit function and form_set_error()
>         actions only take place when the entire form is submitted, and
>         do not take place in an AJAX triggered event (unless it's
>         submitting the entire form).
>
>         1. Fields don't get errors reported against them in the
>         context of a single-element AJAX event. So for example, if
>         you're triggering on a select and there is another required
>         field in the form, form_set_error() will not report the fact
>         that the other required field is still empty.
>
>         2. The _submit() function is *no longer* executed during an
>         AJAX submission, only when the form itself is submitted. It's
>         only run when the whole form is submitted. If you have
>         behavior in your module that depends on this, you'll have to
>         change this.
>
>         I had some contrib code broken by a recent small interface
>         change in D7, and I think we should probably make
>         announcements to this group when these interface changes
>         happen. I haven't figured out a better way of notifying
>         authors who might be affected.
>
>         PS: There is some new documentation on AJAX forms at
>         http://drupal.org/node/684846. Your review and suggestions are
>         welcome.
>
>         -Randy
>
>         -- 
>         Randy Fay
>         Drupal Development, troubleshooting, and debugging
>         randy at randyfay.com <mailto:randy at randyfay.com>
>         <mailto:randy at randyfay.com <mailto:randy at randyfay.com>>
>         +1  970.462.7450
>
>
>
>
>
> -- 
> Randy Fay
> Drupal Development, troubleshooting, and debugging
> randy at randyfay.com <mailto:randy at randyfay.com>
> +1  970.462.7450
>



More information about the development mailing list