I have a simple Drupal form in a custom module where exiting a textfield should retrieve some information about the entered text via ahah to populate a div.
This works fine, except if the user quickly submits the form while the textfield’s ahah event is being processed.
It looks like while the ahah event is being processed the textfield is disabled, which of course means it’s value is not submitted. This means validation fails as the textfield is a required field, so the user is returned to the form with an appropriate error. The textfield is always empty when this happens.
If the user waits for the event to finish, the textfield returns to being enabled and submitting works as expected, as does submitting by using the enter key while in the textfield (the event doesn’t fire then, so the textfield isn’t disabled while it retrieves data).
Is there a way to disable the disabling of the textfield while it’s ahah event is being processed, or some other workaround?
Example of the textfield:
$form['id'] = array(
'#type' => 'textfield',
'#title' => t('Crop No.'),
'#default_value' => $crop['id'] ? $crop['id'] : '',
'#size' => 6,
'#disabled' => $disabled,
'#ahah' => array(
'path' => 'spcs-myspuds/yields/js/crop/description/' . $crop_idx,
'wrapper' => 'spcs-myspuds-yields-edit-crop-description-row-' . $crop_idx,
'effect' => 'fade',
'progress' => array(
'type' => 'none',
),
),
);
Thanks in advance for any help.
I found a workaround.
I had to override
Drupal.ahah.prototype.beforeSubmit, the function that disables the input before the submit (well, duh!).I included the following JavaScript in my module (using
drupal_add_js):This is a copy of
Drupal.ahah.prototype.beforeSubmitas defined in misc/ahah.js with one small change, wrapping the disabling of the input with an if statement to make sure we don’t disable text fields.This is wrapped in a few lines to ensure the re-defining of the prototype happens just once after the DOM is ready.
It might be better to only stop the disabling of the input if a setting is passed such as “disable” => false, but the above worked for the one case in the one page for the one custom module I needed this fix.