Closed (fixed)
Project:
AHAH helper
Version:
6.x-2.2
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
12 Jul 2011 at 23:08 UTC
Updated:
27 Jul 2011 at 03:31 UTC
i have a small form function which i have 2 copies of on a page. at the moment the form is simply an ahah submit button that flips the text of the button back and forth.
the first of these seems to flip back and forth fine as many times as i like.
the second button flips the first time; but the second time the input field has lost the ahah-processed class and when i click the button is submits the page (no ahah).
the code in its entirety is:
function ajax_signup_button_form($form_state, $nid) {
ahah_helper_register($form, $form_state);
global $user;
$signed = false;
$signups = signup_get_signups($nid);
foreach ($signups as $signup) {
if($signup->uid == $user->uid) {
$signed = true;
break;
}
}
// handle button being pressed
if (isset($form_state['values'])) {
if ($form_state['values']['signup'] == "Cancel Alert") {
//signup_cancel_signup($signup, false);
$signed = false;
}
if ($form_state['values']['signup'] == "Alert Me!!") {
//signup_cancel_signup($signup, false);
$signed = true;
}
}
if (!$signed) {
$value = t('Alert Me!!');
}
else {
$value = t('Cancel Alert');
}
$form['signup-button']['signup'] = array(
'#type' => 'submit',
'#value' => $value,
'#name' => 'signup',
'#ahah' => array(
'event' => 'click',
'path' => ahah_helper_path(array('signup-button')),
'wrapper' => 'submit-button-' . $nid,
'method' => 'replace',
'effect' => 'fade',
),
'#prefix' => '<div id="submit-button-' . $nid . '">',
'#suffix' => '</div>',
'#tree' => true,
);
return $form;
}
not entirely sure if this is meant to work with Submit buttons but it seems to work quite well except for this issue; i also do not require any submit handler; i simply process the button click in the same function (as you can see in my code).
Comments
Comment #1
liquidcms commentedcompletely stumbled upon this but i think i have found where this breaks down.
the mutliple buttons on the page have id values assigned to their html input tag as:
edit-signup
edit-signup-1
edit-signup-2
keep in mind that the first one works repeatedly and all the ones after only work once.
i changed (using firebug) the id of the 3rd element to edit-signup and changed the first one to something else as to conflict (edit-signup-blah-blah) and now it is the 3rd one which works continually.
so it would seem that the -n ID designator that formsapi is putting on the form elements is breaking ahah helper.
Comment #2
liquidcms commentedand fixed. . lol.. oops.
changing the line:
$form['signup-button']['signup'] = array(
to:
$form['signup-button']['signup' . $nid] = array(
did the trick.