This patch does the following tasks:

- Adds #ahah_ properties to the forms API.
- Removes upload.js, replacing it with a genericized ahah.js.
- Implements an example of an AHAH form using the upload.module

AHAH is the easiest method of performing page updates in an AJAX-like manner. In a nutshell, javascript makes a request in the background to Drupal. Drupal returns HTML directly to the javascript, which then injects the returned HTML directly into the page. This returned HTML usually targets an existing wrapper div, and either replaces it's content or appends the new HTML.

While fully functional, this patch is meant as a gateway to future improvements. Currently only buttons may have AHAH events attached to them, and the only event supported is on submit.

The following properties are added to the Forms API:

 • #ahah_event (required, default set per input type)
    Currently only "click" supported for button input types, in the future, "change", "blur", etc. could be supported)
 • #ahah_path (required)
    The path Drupal path where the HTML will be generated and returned.
 • #ahah_wrapper (required)
    The HTML id attribute of a DIV (or other element) where returned HTML from the #ahah_path will be inserted.
 • #ahah_method (optional, default set to "replace")
    Where the HTML should be inserted relative to the wrapper. Options include "prepend", "append", "replace", "before", and "after"
 • #ahah_effect (optional, default set to "none")
    What effect should be used when inserting the new HTML. Options include "slide", "fade", and "none". Most <a href="http://interface.eyecon.ro/demos/ifx.html">effects supplied by Interface Elements</a> should work also if installed.

To demonstrate, a usage scenario is included to update the upload.module. Below is the key code necessary to create an AHAH form.

    // Create a wrapper for AHAH form update/replacement
    $form['attachments']['wrapper'] = array(
      '#prefix' => '<div id="attach-wrapper">',
      '#suffix' => '</div>',
    );
    // Add the form.
    $form['attachments']['wrapper'] += _upload_form($node);

    // Add an AHAH submit button.
    $form['new']['attach'] = array(
      '#type' => 'submit',
      '#value' => t('Attach'),
      '#name' => 'attach',
      '#ahah_path' => 'upload/js',
      '#ahah_wrapper' => 'attach-wrapper',
      '#submit' => array(),
    );

Much of this work has been based off the work by Tao Starbow in his ahah_form module.

Comments

chx’s picture

Status: Needs review » Needs work

-p missing from the patch, almost impossible to review.

chx’s picture

Why only changing the elements you changed? What's an #ahah_path? And there are TAB characters in the patch.

chx’s picture

oh, sorry i see #ahah_path explained, now. Still tehre is much to be explained. For example you have "Currently only buttons may have AHAH events attached to them, and the only event supported is on submit." and yet checkbox and radio is changed. I am confused.

quicksketch’s picture

Status: Needs work » Needs review
StatusFileSize
new8.8 KB

Thanks chx, sorry about the missing -p. Attached is a patch with -p and the offending tab removed.

There was a minor change to upload_js() to make the "list" and "delete" checkboxes stay checked when using an AHAH upload and replacement. In system.module's system_elements(), the "checkboxes" type was moved below the "checkbox" type just to make the ordering consistent.

quicksketch’s picture

StatusFileSize
new15.12 KB

The previous patch was missing the new ahah.js file.

quicksketch’s picture

StatusFileSize
new14.95 KB

Ah, I left some #ahah_event parameters in for checkboxes and radios. I hadn't realized. Here's a patch with the #ahah_event removed from radios and checkboxes types, since they are not yet supported.

chx’s picture

Now, I like this but let's see what Eaton has on it.

moshe weitzman’s picture

subscribe

eaton’s picture

Category: feature » task
Status: Needs review » Reviewed & tested by the community

Just took this patch for a spin and file uploading is working fine. The changes here make sense -- in the future, we may figure out a cleaner, more generic way of handling the configuration/setup side of the AHAH stuff, but this is a big step forward for core. Getting this piece in, and evolving it as we learn more, is a good thing. RTBC.

I've also changed the category from 'feature request' to 'task' -- this is another piece in the puzzle for FAPI3's clean and secure AHAH support.

eaton’s picture

Status: Reviewed & tested by the community » Needs work

Whoops.

I just did a quick check and had missed an issue -- the code does not currently work with clean URLs enabled...

quicksketch’s picture

I've double and triple checked the clean URLs support. It should work regardless. Could you give it another shot Eaton?

eaton’s picture

Status: Needs work » Reviewed & tested by the community

False alarm. I had hosed my install with another unrelated patch and it interfered with my re-testing. I just ran it through on a clean install and it works fine. Thanks! ;)

dries’s picture

Status: Reviewed & tested by the community » Needs work

I haven't reviewed this patch yet, but its documentation is lacking. In the issue, you carefully explain what AHAH is, and what parameters are mandatory. None of this knowledge is carried over to the actual code/patch.

I'll review the patch when the documentation is a bit more fleshed out.

eaton’s picture

This raises an important question: where SHOULD we document behavior that is controlled by FormAPI properties? There are no new functions added by this patch to serve as a base for PHPDoc details, etc.

eaton’s picture

Status: Needs work » Needs review

Dries, actually this is precisely what contrib/docs/developer/forms_api_reference.html is for. That file should be updated once this goes in to note the new FAPI properties. The new properties, and some minor changes to upload.js to make it the generic ahah.js, are the only real changes made by the patch.

After reviewing, there *is* no good place to put the documentation in the patch itself.

quicksketch’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new14.84 KB

I've written up a patch for documentation of the new properties. Like other properties in form.inc, the documentation is so extensive that inline documentation is not adequate. This applies to the form_api_reference.html file under docs/developer/topics.

Since there isn't any change to the code, I'll mark as RTBC again. The documentation really should be taken up as a separate issue, but committing the documentation doesn't make any sense until the code they document is included. :)

quicksketch’s picture

StatusFileSize
new143.67 KB

Here's the HTML file with the patch applied.

quicksketch’s picture

StatusFileSize
new14.83 KB

Patch with all the links and anchors working :P

dries’s picture

Status: Reviewed & tested by the community » Needs work

The documentation patch looks a bit weird with those hardcode/nested font-tags.

However, I think we should extend the PHPdoc.

1. Specifically, let's extend theme_form_ahah() so developers/designers know how to use this function. Explain what 'AHAH' is and explain when they might want to overwrite this specific function. Thanks!

2. At the top of ahah.js, explain what ahah is and what this file is about.

3. Is there a reason to put '.prototype.' in the function names in ahah.js?

eaton’s picture

The documentation patch looks a bit weird with those hardcode/nested font-tags.

To his credit, that's the format of the existing reference document. Reformatting that entire document to be cleaner HTML is probably outside the scope of just this issue.

However, I think we should extend the PHPdoc.
1. Specifically, let's extend theme_form_ahah() so developers/designers know how to use this function. Explain what 'AHAH' is and explain when they might want to overwrite this specific function. Thanks!

Ideally, they'll never override this at all -- like theme_node(), its purpose is to handle core functionality that needs to happen during the theming process automatically. The only time they would want to override the function is if they were swapping out an alternate implementation of ahah.js. They would never directly call theme('ahah',...) either; instead, this injects client side script and handles the wrapper div for the AHAH-controlled chunk of HTML, if I understand correctly.

We could make a note in the PHPDoc for that function that it's used internally by FormAPI, not unlike theme_checkboxes or theme_textarea. But we still face the difficulty of documenting behaviors that are driven by arbitrary array properties in our #structures. it's enough to make one long for PHP classes... :-)

I good explanation at the top of ahah.js would definitely be helpful, though.

quicksketch’s picture

Indeed the only reason this is a theme function at all is because it adds javascript to the page header (and therefor markup). They should never need to over ride this function unless they want to provide a custom ahah.js or use some alternative means for AHAH replacement. (I guess that's what I'll put in the PHP Doc :)

The font tags are the default output by PHP 4 when using the code format filter. Using PHP 5 will switch the method to inline style tags if that's preferable.

The .prototype is necessary to actually instantiate a new javascript object. We could rewrite the extension not to use OO properties, but this file is modeled after upload.js, which used the same method. Changing methodologies will require further rewrites in drupal.js.

I'll improve the documentation further and resubmit. Thanks!

quicksketch’s picture

Status: Needs work » Needs review
StatusFileSize
new15.68 KB

Improved documentation in ahah.js and PHPDoc for theme_form_ahah(). This patch is squeaky clean :)

quicksketch’s picture

I'm not rerolling the documentation patch as it's already inline with the current documentation. If we want to switch to using spans and styles, we should take that up with the documentation team and update the whole forms API document. Let's not hold this up because of something way beyond the scope of adding a feature. I doc'd this feature like crazy, it should be sufficient for the initial commit.

eaton’s picture

Status: Needs review » Reviewed & tested by the community

Reviewed and re-checked; the new comments make it clear what the theme function is for, and the changes to the doc make it pretty straightforward, adding new stuff to form elements. Very cool!

dries’s picture

OK, this looks sane. Thanks for the updates/clarifications. I'll commit this patch on Monday, unless a jQuery expert comes in an veto's the approach.

I reviewed another jQuery patch today -- a behaviors patch that Nedjo was working on. I'd like to see that patch land as well. Not sure, but there might be some conflicts. If you have time, maybe take a look at that one too. See http://drupal.org/node/120360.

nedjo’s picture

Status: Reviewed & tested by the community » Needs work

This is a nice addition and well coded. I haven't tested, just looked over the code.

I particularly like how this patch takes an existing behavior that's hard-coded to a specific use case and generalizes it so that it fully meets the original use case but is also flexible enough to meet a range of other ones. This is exactly what we need to be doing.

Comments:

1. Theme use

theme_form_ahah() is not for theming (it returns no rendered content), so a theme function feels wrong. If the aim is to enable overriding of the ahah handler, maybe this needs to be done at the module level.

2. Drupal.redirectFormButton

I've had numerous problems with this function. It was designed for the narrowly-conceived use case of upload.js, where we have an additional submit button in a part of a form. The function creates problems when, e.g., form submission may be triggered by actions other than clicking on a submit button (like hitting enter, or trying to submit programmatically), situations that are complicated by cross-browser issues.

When we try to attach behaviors to the form button, they get missed when users e.g. hit enter to submit. This doesn't happen in upload.js (there are no text fields in the upload UI) but is likely to occur as soon as we try to attach behaviors to other forms.

Specifically, in the Active Edit module, I load inline form snippets (click on a node title, load a form for editing just the title, submit, the title is updated). When I tried to do this with redirectformbutton, it failed if a user hit enter to submit the form (regular form submission, full page reload).

After much work trying to use redirectFormButton, I ended up replacing its use with a function called Drupal.redirectFormSubmit, in jstools.js, which is much more flexible. It doesn't wait until a user hovers over a button to attach the behavior, but presumably could be used in that way if needed. I wonder if the same should be done here.

3. Variable names with $

  var $wrapper = $(this.wrapper);
  var $button = $(this.id);
  var $progress_element = $(this.progress.element);

Variables shouldn't have the $ signs.

4. basePath


drupal_add_js(array('system' => array('basePath' => base_path())), 'setting');

This setting doesn't seem to be used in the patch.

5. Name of behavior

This is not a generic AHAH framework but rather is specific to form submission. We should find a more descriptive name. In general we name behaviors for their action rather than their method. Some suggestions: submit, formSubmit, activeSubmit.

6. Full form submission

upload.js is premised on the limited use case of submitting a form so that we can update only a portion of the UI prior to subsequent regular form submission.

What will happen if developers try to use the ahah behavior for full, regular form submission?

(I've implemented full AJAX form submission in the ajaxsubmit module (part of Javascript Tools). There I've tried to work through questions like returning status messages, resetting form elements with error markers, etc. This might be useful for reference, though probably in a follow up patch.)

Altogether, very nice work.

Probably the only one of my comments here that would require a lot of work to address is 2, redirectFormButton. It might be okay to apply this now and leave fixing of redirectFormButton for later. It would be useful first to confirm that this issue exists.

Steps to reproduce this problem:

a. Create a subform that needs to be submitted separately and contains a textfield.
b. Hit enter from within the text field.
c. Observe result. If I'm following the code correctly, it will be regular form submission rather than the expected AHAH.

As for the relation with http://drupal.org/node/120360, I don't foresee any problems. We've already tested upload.js's conversion, and this should be almost identical.

quicksketch’s picture

Replies to nedjo within :)

1. Theme use

theme_form_ahah() is not for theming (it returns no rendered content), so a theme function feels wrong. If the aim is to enable overriding of the ahah handler, maybe this needs to be done at the module level.

The theme function has a drupal_add_js(), and therfor adds markup to the page. The comments in the code reports as much and explains that over ridding should only be done if someone would like to write their own replacement ahah.js.

2. Drupal.redirectFormButton ...

Yes this function has inherent problems with it's functionality. I'm using it to keep the patch short and make an introduction to using AHAH in the Drupal API. In system.module, the default events are only set on buttons, #ahah_event = 'submit'. In the future, redirectFormButton will be replaced and #ahah_event will be set on every form element type (blur for textfields, change for selects and radios, etc).

3. Variable names with $

var $wrapper = $(this.wrapper);
var $button = $(this.id);
var $progress_element = $(this.progress.element);

Variables shouldn't have the $ signs.

Setting variables with dollar signs is common practice when setting variables that are jQuery objects. Setting a jQuery variable and reusing it is more efficient than repeatedly doing $(this.wrapper), because it doesn't require jQuery to traverse the DOM a second time.

4. basePath

drupal_add_js(array('system' => array('basePath' => base_path())), 'setting');

This setting doesn't seem to be used in the patch.

Hmm, I had used this variable in an earlier iteration. Should it be removed? Many jQuery contrib modules add this variable as it's required for a lot of functionality (simplemenu, fivestar). I'll remove it.

5. Name of behavior

This is not a generic AHAH framework but rather is specific to form submission. We should find a more descriptive name. In general we name behaviors for their action rather than their method. Some suggestions: submit, formSubmit, activeSubmit.

As stated above, the idea is to make this work on all form elements, so ahah is appropriate.

6. Full form submission

upload.js is premised on the limited use case of submitting a form so that we can update only a portion of the UI prior to subsequent regular form submission.

What will happen if developers try to use the ahah behavior for full, regular form submission?

(I've implemented full AJAX form submission in the ajaxsubmit module (part of Javascript Tools). There I've tried to work through questions like returning status messages, resetting form elements with error markers, etc. This might be useful for reference, though probably in a follow up patch.)

The ahah functionality should always augment an existing functionality, not replace it. If the use clicks the button with javascript disabled, the form should have a non-javascript equivalent of the functionality. If the user attached this to the actual form submit button, it should work fine. Because this simply redirects the form action to a hidden iframe (in drupal.js), the entire form is submitted normally. I suppose you could add a #submit handler to the form to make it return part of the page rather than a whole new one. I hadn't thought of this use-case, but even so, I think it would be better handled in a followup patch.

Nedjo, could you review a second time and post if you think changes are necessary with these responses in mind?

quicksketch’s picture

Wow, I'm terribly sorry about my unclosed quotes! Preview is my friend... preview is my friend...

recidive’s picture

Can we modify FAPI so setting #ahah_path would be optional, and even don't need a (required) menu item/callback. This way we could make access check consistent and avoid security issues. The approach is simple, drupal_get_form, drupal_render, etc should check if it is an AHAH request and return a sliced JSON form if so.

Almost every form items already have wrappers (the ones that call theme_form_element()). Can we use these wrappers, so instead of the #ahah_wrapper we use #ahah_element. For group of form fields we could use fieldsets.

$form['dynamic'] = array(
  '#type' => 'fieldset',
);
$form['dynamic']['text'] = array(
  '#type' => 'textfield',
  '#title' => t('Text'),
);
$form['submit'] = array(
  '#type' => 'submit',
  '#value' => t('Submit'),
  '#ahah_path' => 'my_module/js',
  '#ahah_element' => 'dynamic',
);

Note: Fieldset is one (and probably the only) form field that currently doesn't have wrappers.

Why the AHAH stuff is restricted only to 'button' and 'submit' form files (this is what the docs says, at least)? It would be great and not so complex to implement, bringing those capabilities to other form fields, such as 'select', it would allow server side dynamic select fields, e.g. you have two selects. When you change one, the other is updated.

$form['select_one'] = array(
  '#type' => 'select',
  '#title' => t('Choose'),
  '#options' => array(1, 2, 3),
  '#ahah_element' => 'select_two',
  // The following property should be optional.
  '#ahah_event' => 'change',
);
$form['select_two'] = array(
  '#type' => 'select',
  '#title' => t('Choose'),
  '#options' => array(1, 2, 3),
);

Note: Obviously, it would need to some logic to change options for the second 'select' based on the option selected on the first.

To avoid using (and get rid of) the Drupal.redirectFormButton function, one option adding the 'official' jQuery plugin 'forms'. AFAIK, it automatically detects if the form is an multipart/upload form and if so, it uses the iframe approach, if don't it uses standard jQuery.ajax calls.

I agree with Nedjo that the term 'ahah' is not so descriptive. I was wondering if we could we just call it #bind_to. So with the changes above, plus changing #ahah_element / #ahah_wrapper to #bind_to we would have:

$form['dynamic'] = array(
  '#type' => 'fieldset',
);
$form['dynamic']['text'] = array(
  '#type' => 'textfield',
  '#title' => t('Text'),
);
$form['submit'] = array(
  '#type' => 'submit',
  '#value' => t('Submit'),
  '#bind_to' => 'dynamic',
);

So the other property names could be use the #bindings namespace, e.g. #bindings_effect, #binding_path, etc. Or, instead, the #bind_to property could be set to an array:

$form['submit'] = array(
  '#type' => 'submit',
  '#value' => t('Submit'),
  '#bind_to' => array('element' => 'dynamic', 'effect' => 'fade', 'path' => 'custom/path', 'event' => 'click'),
);

And finally, are there other core forms we can add these capabilities to?

Anyway, great patch! I just think we could make this more extensible by implementing some of the features above if we have time (2 days from the code freeze :( ).

nedjo’s picture

@quicksketch

Thanks for the responses, However, please try to consider more closely the potential merits of comments. It feels like a poor use of commenters' time if you don't. There's little sense in my having to repeat the same comments. That said, here goes.

1. Theme function

The theme function has a drupal_add_js(), and therfor adds markup to the page.

It "returns no rendered content", as I commented. It adds JSON data, which is not themed. We have many existing calls to drupal_add_js() (and drupal_add_css()) that are not in theme functions. Should these all be moved to the theme layer? I think it's obvious they shouldn't.

Rather, the point here is to focus on the question of enabling override. Is this appropriate in the theme (and therefore does it justify this bending of the purpose of theme overrides)? My feeling is, no. That's not what the theme system is for. It would be better to leave this out and make this a non-theme function. Or, as I said, "If the aim is to enable overriding of the ahah handler, maybe this needs to be done at the module level."

2. redirectFormButton

In system.module, the default events are only set on
buttons, #ahah_event = 'submit'.

My point is that developers trying to use this - attaching a behavior to a button - will get unexpected results (no AHAH) and potentially broken behaviors (if the JS-processed content breaks without AHAH) due to non-button-click submits. Is this true? Can you try the test I suggested and report back? If it is true, this should at least be documented. Ideally it would be fixed.

3. Variable names with $

Setting variables with dollar signs is common practice when setting variables that are jQuery objects

This is not a convention used as yet in Drupal core. If you want to introduce it, you should take the time to convert as well the many existing variable references to jQuery objects in core. It will also need documenting.

5. Name of behavior

As stated above, the idea is to make this work on all form elements, so ahah is appropriate.

Your comment misses my main points. Here's mine again:

This is not a generic AHAH framework but rather is specific to form submission. We should find a more descriptive name. In general we name behaviors for their action rather than their method. Some suggestions: submit, formSubmit, activeSubmit.

To restate: this is not AHAH in general, this is a specific behavior related to form submit buttons. It may later be expanded to other form elements, but that doesn't mean that 'ahah' is descriptive. What would be? I offered some suggestions. You might come up with others.

6. Full form submission

If the user attached this to the actual form submit button, it should work fine. Because this simply redirects the form action to a hidden
iframe (in drupal.js), the entire form is submitted normally

As I mentioned, the specific problems of full form submission including returning status messages and form element errors. Without solutions for these problems, the current ahah.js applied to a regular submit button presumably would break e.g. validation (there is no way to inform a user of the difference between failed validation and successful submission). So it probably wouldn't work fine. Probably not a big problem at this point. But something to note, and probably to document.

Again, these comments are offered in the context of strong support for the patch. Thank you for your work.

quicksketch’s picture

@nedjo:

It "returns no rendered content", as I commented. It adds JSON data, which is not themed. We have many existing calls to drupal_add_js() (and drupal_add_css()) that are not in theme functions. Should these all be moved to the theme layer? I think it's obvious they shouldn't.

I disagree here. If it adds markup to the page, it should be in a theme function. All the current calls to drupal_add_js() in all of form.inc are inside of theme funcitons. If it adds markup, it's in a theme function. You probably wouldn't over ride theme_textarea() or theme_fieldset() to change the javascript either, but it's there if you need it.

My point is that developers trying to use this - attaching a behavior to a button - will get unexpected results (no AHAH) and potentially broken behaviors (if the JS-processed content breaks without AHAH) due to non-button-click submits. Is this true? Can you try the test I suggested and report back? If it is true, this should at least be documented. Ideally it would be fixed.

Try to disable javascript and upload a file. It works file even without the ahah. All form elements should behave in a similar manner. AHAH is meant to improve user interface, not replace it.

I'd also like to keep the behavior as 'ahah' or something more general like ahahChange or ahahUpdate. ahahSubmit doesn't make sense in all contexts. The code is currently written so it could work with any form element, but the actual submission process and Drupal.redirectFormButton needs to be updated to support additional elements. Naming the behavior 'submit' wouldn't make any sense if it modified the page when a user changed a select item. It is intended to extend to all form elements, but hasn't yet reached that point in development.

@recidive
#ahah_path is absolutely necessary. If it doesn't make an AHAH request, it's not really ahah is it?
#ahah_event is already optional. Or in actuality it is set to a default which will rarely need to be changed.
I think I've already stated several times that this will eventually support all form elements.

I've already written a patch to add AHAH to poll module. I'm waiting for this patch to go in.

At first look I didn't think that the forms jQuery library worked with uploads, I guess it does! http://www.malsup.com/jquery/form/#faq

I'm going to refactor a little bit to take into account the comments here.

quicksketch’s picture

Another correction. In my initial description I said that the only supported event is 'click' for buttons. It is in fact not 'click' but 'submit'. The ahah behavior works even for keyboard-only input. Also, if errors are incurred during the event, they can be displayed in the returned HTML. Try uploading a file with an invalid extension (such as .gz). The message will be returned as part of the replaced HTML.

To everyone, please actually apply the patch before suggesting changes that already exist.

quicksketch’s picture

Status: Needs work » Needs review
StatusFileSize
new13.91 KB

Updated patch with the following changes:

- basePath is removed as a javascript variable added by system.module. I'll put that into a separate patch since it's not needed for this issue.
- Removed the theme_form_ahah() function in preference of a #process function, form_expand_ahah(). We maintain the same ability to over ride the ahah.js file by a hook_form_alter() on the #process function, and it removes the implied connection between a theme function and modifying the display, rather than functionality.
- Removed $ sign from variables in ahah.js. We can add them in a later patch if that becomes convention in Drupal core.

Nedjo and I discussed opportunities for expanding this system on IRC. We decided leaving the behavior as 'ahah' because it can be extended it to all elements, even those not added by the forms API.

The addition of adding the official jQuery forms library is probably too large to fit into this incarnation of the patch. Adding external code is often a controversial issue, so let's wait on adding that functionality for another issue.

eaton’s picture

Status: Needs review » Reviewed & tested by the community

quicksketch + nedjo = rocking.

The idea that poll.module could use actual dynamic updating excites me in ways that are almost scary.

pwolanin’s picture

If you're making these changes, shouldn't upload.module also be changed so:

print drupal_to_js()

is changed to use the new drupal_json() function which sends the right headers?

Also, is this patch doesn't seems to deal at all with form validation issues due to changing form elements - do you avoid that by only doing submits?

eaton’s picture

Also, is this patch doesn't seems to deal at all with form validation issues due to changing form elements - do you avoid that by only doing submits?

I'm not sure what you mean. Do you mean things like, required fields being added to the form, or complex cross-field validation rules being broken by the addition or subtraction of fields? quicksketch is working on a patch to poll.module (currently working, but depending on this patch) that alters the cached copy of the form whenever client-side changes are made, to keep the validation in sync.

How that gets handled woudl really depend on the application of this code. It's probably best to handle it separately.

quicksketch’s picture

Status: Reviewed & tested by the community » Needs work

Also, is this patch doesn't seems to deal at all with form validation issues due to changing form elements - do you avoid that by only doing submits?

If the fields have changed in some illegal manner, Drupal will still throw it's normal validation errors when the entire form is submitted.

I'm marking this down to code needs work because I ran into an issue when writting the poll enhancement. Currently if you use an effect to display the new fields, the entire wrapper is collapsed rather than expanded. I've fixed it and am continuing to test. I'll put up the new patch later today.

eaton’s picture

Would it make sense to roll the poll.module enhancements into the patch as a demonstration of the new functionality? That might help folks get an idea of how it's going to be useful. Or, just keep the patch at the level of functionality it has currently...

pwolanin’s picture

For the poll module, have you looked at the code I have in the book module patch?

I picked Jeff's brain for an hour to get the basic ideas of how to do it, and after stumbling around for a while and getting the starting JS from Dmitri it works well now to replace a second select based on the first: http://drupal.org/node/146425 See book.js and the AJAX callback function in the patched book.module.

nedjo’s picture

Thanks quicksketch for your further work.

In my view the latest patch successfully addresses the issues I identified. I'm not wholly convinced by the name ahah.js but it does for now and I don't have better suggestions. The remaining need is in noting some issues or shortcomings in documentation for the upgrade or for use of the functions:

a. this shouldn't yet be applied to regular submit buttons
b. there may be issues with non-AHAH submission being triggered by user actions in AHAH subforms

The second issue will require a future patch to refactor and improve Drupal.redirectFormButton.

quicksketch’s picture

Status: Needs work » Needs review
StatusFileSize
new13.91 KB

While writing the patch to AHAH enable poll module, I discovered a few problems when implementing multiple AHAH buttons on one page. This updated patch:

- Prevents drupal_add_js() from adding settings twice for one form element, causing a recursion error.
- Properly supports the 'append' and 'prepend' methods of adding injected HTML (used in the poll patch).

This patch is necessary to test the updated AHAH-enabled poll module in this patch: http://drupal.org/node/155870

eaton’s picture

Status: Needs review » Reviewed & tested by the community

Installed and tested. Cleaner and slicker. Thanks for the feedback, nedjo.

eaton’s picture

Waaaait a minute. Those last two patches were the *same!* ;)

quicksketch’s picture

StatusFileSize
new14.39 KB

Oops, I uploaded the last patch twice, so it didn't include the fixes I mentioned in the last post. Here's updated patch that makes the poll patch work correctly. Sorry :P

eaton’s picture

That's more like it. Tested and approved with both the upload and poll modules, and the two cases you mentioned work. Hot.

nedjo’s picture

Status: Reviewed & tested by the community » Needs work

I'm working on updating this for the Drupal.behaviors patch that went in.

nedjo’s picture

StatusFileSize
new3.24 KB

I have to head out (holiday long weekend here, family vacation). I've drafted an update but not tested it. Here is the revised js file. If someone could pick up where I've left off that would be great.

quicksketch’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new10.77 KB

Thanks for the update nedjo!

I corrected a few indentation spaces in your js file and rerolled the patch to include it. Tested thoroughly and works with the included upload module changes and the poll patch. I was a little curious about the "ahah-processed" class added to the element, but it seems as though that debate happened in the previous issue and has been made a standard. Everything looks great!

quicksketch’s picture

StatusFileSize
new14.35 KB

Flippin' cvs :P

Here's the patch with the ahah.js file added.

quicksketch’s picture

Is this patch slated for inclusion in D6? While it clearly contains UI improvements, it expands the API quite a bit. It's my fault for getting started so late in the cycle, but this is a very important piece of improving the user interface in Drupal.

Frando’s picture

[21:05] Dries_: the AHAH/Poll related patches, would those be UI, or can I mark 'em as postponed? It's OK either way ;)
[21:05] eaton: these are usability improvements

Frando’s picture

Hm, once again I forgot the HTML filter. So switch eaton and Dries - these aren't the speakers name (HTML filter ate them) but the adressed nick.

dries’s picture

I think this qualifies as a usability improvement -- especially with the poll module improvements.

eaton’s picture

Seeing an IRC quote of Dries asking me how to classify an issue can only improve my reputation!

*slips Frando a $20*

seriously, though. the poll.module improvements that this makes possible are really exciting. I think it's the first clean update we've made to poll.module since version... Um. Something? :-)

quicksketch’s picture

Woot! Great, then I'll continue with more usability improvements.

There are more places left in core for better javascript :)

dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

Anonymous’s picture

Status: Fixed » Closed (fixed)
beginner’s picture

Category: task » bug
Priority: Normal » Critical
Status: Closed (fixed) » Needs review

He: the documentation patch, comment #18 above, never got committed.
http://drupal.org/node/154398#comment-573549
6 months after the fact, there is still no proper documentation for this feature.

gábor hojtsy’s picture

Project: Drupal core » Documentation
Version: 6.x-dev »
Component: forms system » Documentation in CVS

Documentation problem. The patch is not against 6.x core, but the contribution CVS hosted documentation.

bdragon’s picture

Assigned: Unassigned » bdragon

This is nuts.
I will commit this.

bdragon’s picture

Status: Needs review » Fixed

Reformatted to match current documentation and committed.

pwolanin’s picture

Status: Fixed » Needs work

Looks like something has changed since those docs were written. The actual form builders in use look like:

modules/poll/poll.module:239:    '#ahah' => array(
modules/poll/poll.module-240-      'path' => 'poll/js',
modules/poll/poll.module-241-      'wrapper' => 'poll-choices',
modules/poll/poll.module-242-      'method' => 'replace',
modules/poll/poll.module-243-      'effect' => 'fade',
modules/poll/poll.module-244-    ),

So there is only 1 form element (#ahah) not several (#ahah_path, #ahah_event, etc).

pwolanin’s picture

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

here's a major fixup of this mess.

pwolanin’s picture

StatusFileSize
new30.5 KB

committed this version - but still needs review. PLEASE!

beginner’s picture

I read everything, checked that all the links work.

I corrected some typos, improved the grammar in some places.
I added a list of default values in #ahah['event'].

since everywhere the elements are in alphabetical order, I reordered the list:

#ahah
Used by: button, image button, submit, checkbox, password, radio, select, textarea, textfield

Thus I found that select was missing from the list with default values, and radios was missing from the list above.
I have not touched the list of default values at the top of the page, but I have added radios and select to the copy of the list in #ahah event.

http://cvs.drupal.org/viewvc.py/drupal/contributions/docs/developer/topi...

Here is the only reason I don't set this issue as fixed:

#ahah['path'] has Used by: button, submit but the other #ahah elements don't have such a list. Is this list complete? Should it be deleted?

beginner’s picture

And thanks bdragon for getting the ball rolling, and for Peter for taking the time to update the docs.

pwolanin’s picture

@beginner - it wasn't clear to me whether this worked with radios (based on form.inc) so I left it off. If it does work (is there an example?) then obviously it should be included

#ahah['path'] does not need such a list - I'll take it off.

pwolanin’s picture

StatusFileSize
new18.52 KB

#ahah['progress'] was totally undocumented - added a section for that.

By experimentation and examination of the code, #ahah seems not to work for radios or checkboxes (correct me if I'm wrong). So those are excluded.

Attached additional changes committed.

bdragon’s picture

@ #68:

Confirmed by visual inspection.

The #process functions expand_checkboxes() and expand_radios() do not do any ahah handling.

pwolanin’s picture

@bdragon - are you satisified with the docs now?

betz’s picture

Project: Documentation » Drupal core
Version: » 7.x-dev
Component: Documentation in CVS » documentation

Changed the component to reflect the new component categorization. See http://drupal.org/node/301443

Patch failed to apply. More information can be found at http://testing.drupal.org/node/13899. If you need help with creating patches please look at http://drupal.org/patch/create

Patch failed to apply. More information can be found at http://testing.drupal.org/node/13898. If you need help with creating patches please look at http://drupal.org/patch/create

Patch failed to apply. More information can be found at http://testing.drupal.org/node/13900. If you need help with creating patches please look at http://drupal.org/patch/create

quicksketch’s picture

Component: documentation » forms system
Assigned: bdragon » Unassigned
Category: bug » task
Priority: Critical » Normal
Status: Needs review » Closed (fixed)

Oh shut it DrupalTestbedBot.