I have some code that is working perfectly with a select box. Changes to the box issue a callback and I'm able to repopulate the screen. If I add an additional element on the form with type 'file', the select is no longer working. I've looked at the _POST coming back and the default_value is simply not there. It works fine if I remove the element. I've looked at the issue 399676 and it doesn't seem to apply. I tried the code change and no effect. The problem is that the data is not even in the _POST.

The interesting thing is that all other elements on my form that are tied to AHAH elements work perfectly. It's just the select field that has the bad behavior. The file field itself works as well.

Any ideas?

Comments

rfay’s picture

Category: bug » support

AHAH with file elements is a bit of a different thing. Sorry to offer no help, but I've never done that for the Examples AHAH example. You'll find it in CCK though, in the filefield implementation.

A file upload example for D6 would be a welcome addition to the AHAH example.

swood’s picture

I actually tracked the problem down. There seems to be a resolution in D7 described in #995854: #ajax doesn't work at all if a file element (or enctype => "multipart/form-data") is included in the form regarding a checkbox. Unfortunately, the same solution wouldn't work here, but I was able to use glean a little insight from that discussion. The problem as it turns out here is that the current ahah element is disabled prior to the post. In the case of no file submission, the ahah post is sent as json. If a file is included, the post is sent as multipart and the disabled element is missing. I'm not quite sure the specifics here but it seems that the only elements that it has a problem with are selects and checkboxes. Buttons a multi-select boxes don't have a problem (?). To fix the issue, I modified ahah.js to prevent the select-one element from being disabled. That resolved it. I haven't fully tested with other elements yet to see which others need to be prevented.

Drupal.ahah.prototype.beforeSubmit = function (form_values, element, options) {
  // Disable the element that received the change.
  if (this.element.type != 'select-one')
    $(this.element).addClass('progress-disabled').attr('disabled', true);
erikwebb’s picture

That does seem to resolve the issue, but apparently that's not a very good solution as discussed in #80 of the linked thread. I'm still trying to come up with a better solution myself.

This seems like a big issue - SELECT + FILE = broken AHAH?

kars-t’s picture

Status: Active » Fixed

Hi

I am closing this issue to clean up the issue queue. Feel free to reopen the issue if there is new information and the problem still resides. If not please make sure you close your issues that you don't need any more.

Maybe you can get support from the local user group. Please take a look at this list at groups.drupal.org.

Status: Fixed » Closed (fixed)

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

har-wradim’s picture

Here is my work-around.
Use an extra hidden field, which is managed by the select via js:

$form['main_field'] = array(
		'#type' => 'select',
		'#options' => $options,
		//assign selected value to the hidden field before posting the form
		'#attributes' => array('onchange' => "document.getElementById('edit-hidden-field').value = document.getElementById('edit-main-field').value;"),
		'#ahah' => array(
					'event' => 'change',
					'path' => ahah_helper_path(array('target')),
					'wrapper' => 'target-wrapper',
		),
	);
//this field will actually be posted
$form['hidden_field'] = array('#type' => 'hidden');
//get the current value from the posted hidden field
$current_value = isset($form_state['values']['hidden_field']) ? $form_state['values']['hidden_field'] : $default_option;