I use the advanced polls module in Drupal 7. I am trying to alter the behaviour so that the vote is submitted as soon as the radio button is selected (without having to hit Vote).
The module is using an ajax callback:
$form['submit'] = array(
'#type' => 'submit',
'#ajax' => array(
'callback' => 'advpoll_form_submit',
'wrapper' => 'advpoll-form-' . $values->nid,
'name' => 'submit1',
),
'#id' => 'edit-submit-advpoll-' . $values->nid,
'#value' => t('Vote'),
);
How can I invoke this callback with radio buttons?
I am happy for a quick and dirty javascript/jQuery solution as time is a real factor.
I have tried a jQuery solution:
$('input[type="radio"]').change(function() {
$('#advpoll-form-296').trigger('click');
});
However this is not invoking the action as expected.
I cannot call submit() as I don't want to cause a page reload.
I have managed to get my original code to fire by adding a click event to the ajax array in the .module file.
advpoll.module:
function advpoll_choice_form($form, &$form_state, $values) {
$form['submit'] = array(
'#type' => 'submit',
'#ajax' => array(
'callback' => 'advpoll_form_submit',
'wrapper' => 'advpoll-form-' . $values->nid,
'name' => 'submit1',
'event' => 'click', //Added click event
),
'#id' => 'edit-submit-advpoll-' . $values->nid,
'#value' => t('Vote'),
);
I am aware I should not override code within the module. How would I go about getting this into a theme hook?
$('#advpoll-form-296').submit();
. The Drupal way is more complicated