Hi,

I was playing around with the AHAH D6 dependent dropdown module and I came to following issue:

Suppose the form contains not only those 2 fields ("Master Dropdown" and "Dependent Dropdown"), but also some others and those are required.

Then after each change of "Master Dropdown" as long as the other required fields are not filled in yet, we get a warning message that this field is required (please see screenshot).

So the form tries to submit and of course gets validated before that and the warning pops out. This shouldn't happen as far as I can understand this code in the module (Line 121 in dependent_dropdown.inc)

function ahah_example_dropdown_submit($form, &$form_state) {
  // If an AHAH submission, it's just the dependent dropdown working.
  if (!empty($form_state['ahah_submission'])) {
    return;
  }
  // and so on...

Any help is greatly appreciated! Thanks in advance!

CommentFileSizeAuthor
Clipboard01.jpg55.95 KBdrupov

Comments

rfay’s picture

Please try providing a '#validate' function array for the item in question. Instead of using the fairly crude "required" validator, use a custom #validate instead and see if that can get you out of trouble. In the validator, you can look at $form_state['clicked_button'] to learn a little more about the context you're in.

drupov’s picture

Hi,

thanks for your quick reply! I was able to do things the way you pointed me at #1 so thanks once more for the idea, but I still have problems and here's why:

I'm using the dependent dropdown code together with the webform module. My webform has about 30 fields and most of them have to be required. Due to this I'm facing following tasks here:

- if I write a custom validation function in a custom module for this webform I would have to hardcode the validation checks for the fields that are being required on every one of them. While you can somehow iterate through them it's still much more convenient, user friendly and overviewable to set those required settings in the UI of webform.

- most of those fields have further validation requirements like email address, number components and so on. These settings are also set very conveniently in the UI of webform and would be so complex to validate manually for so many fields...

- last and least, but still important... My asterisks (*) indicating that fields are required are gone, if I don't use the required setting. Re-theming them upon my custom validation would also cause lots of headaches.

I hope someone can come up with an idea to solve this problem on the dependent dropdown layer.

Thanks in advance!

rfay’s picture

Maybe somebody will chime in here.

Your asterisks are provided by the default validation function, so you can look at the FAPI code and add that bck in.

Of course, as you already suspect, you may be trying to graft something into webform that shouldn't be there :-)

I didn't know you were doing a form alter. You may have made the mistake of overwriting the existing '#validate' array instead of adding to it or altering it. With an existing form you would need to:

1. Inspect the #validate array to find the handler that's causing trouble, and remove it.
2. Add your validate handler (perhaps in its place)

-Randy

drupov’s picture

I just wanted to confirm that the contents in the #validate array were causing this behavior.

Just like the Examples modules handles the AHAH-submission, you have to make a change in the validation function to see what triggers the submission. If it's AHAH - then just do nothing, if it's the normal submission, then let all the validation work be done.

In my case, in the webform module, the module assigns its default validation and submission functions to the form. Now even if you check what kind of submission happened you still have to get (temporarily) rid of webforms' default submission, as it gets run anyway, as long as it is in the '#submit' array.

In hook_form_alter this could look like this:

// Webform submissions have a handler for paged submissions,
// so we need to keep that function.
$first = array_shift($form['#submit']);
// The new '#submit' array contains then only the value we saved in $first,
// as well as our custom submit function.
$form['#submit'] = array($first, 'dependent_dropdown_form_submit');

You can then call the default function from inside your custom function, e.g.:

if (!empty($form_state['ahah_submission'])) {
  // It was the AHAH-submission, do nothing.
  return;
}

if ($form_state['clicked_button']['#id'] == 'edit-submit') {
  $form_state['rebuild'] = FALSE;
  // Call the default webform submit function
  return webform_client_form_submit($form, &$form_state);
}

The validation would work in the same manner.

Thanks rfay for pointing me in the right direction!

mile23’s picture

Status: Active » Closed (works as designed)

So no other work required on this?