We're trying to figure out the approved way using the states api to detect when a form element is added to the form by an ajax callback.
We've tried all the different states that are mentioned here.
Our code was working with 7.13, but when we updated to 7.15 it stopped working.
Our code basically hides the comments form until the user votes on a poll. Once they voted, it hides the message, and shows the comment form.
Here is our code that worked for 7.13; (This works with the Ajax Poll module)
// Provide an appropriate message about casting a vote when the voting form is visible
$comment_form['message'] = array(
'#type' => 'fieldset',
'#tree' => FALSE,
'#id' => 'comment-message',
'#attributes' => array(),
'content' => array(
'#markup' => t('To comment on this question, please first cast a vote for one of the options above.'),
),
'#states' => array(
'invisible' => array(
".poll #edit-submit" => array('value' => 'Cancel your vote'),
),
'visible' => array(
".poll #edit-vote" => array('value' => 'Vote'),
),
),
);
// Provide the comment form when the results are visible.
$comment_form['container'] = array(
'#type' => 'fieldset',
'#tree' => FALSE,
'#id' => 'comment-wrapper',
'#attributes' => array(),
'#states' => array(
'invisible' => array(
".poll #edit-vote" => array('value' => 'Vote'),
),
'visible' => array(
".poll #edit-submit" => array('value' => 'Cancel your vote'),
),
),
);
Comments
Comment #0.0
guypaddock commentedCorrect indentation.
Comment #1
nod_tag
Comment #1.0
nod_Typo correction.