I'm trying to figure out how to trigger an element with a link in a form using trigger_as.
I tried the following snippet. The button ajax callback works, but the link doesn't. The link does seem to use the right name and value in trigger_as (as seen in the js console), but the post callback doesn't return anything.
$form['add_more'] = array(
'#type' => 'submit',
'#value' => t('Add another item'),
'#attributes' => array('class' => array('add-more-submit')),
'#submit' => array('field_add_more_submit'),
'#name' => 'result_fields_add_more',
'#ajax' => array(
'callback' => '__update_fields',
'wrapper' => 'example-wrapper',
'effect' => 'fade',
),
);
$form['add_more_link'] = array(
'#type' => 'link',
'#title' => t('add'),
'#href' => '#',
'#process' => array('ajax_process_form'),
'#ajax' => array(
'callback' => '_update_fields',
'wrapper' => 'example-wrapper',
'effect' => 'fade',
'event' => 'click',
'trigger_as' => array(
'name' => 'result_fields_add_more',
'value' => t('Add another item'),
),
),
);
I tried to follow this example, but didn't work: http://drupal.org/node/753270#comment-2910362 I also didn't find an ajax link in the rules module, only a button with an ajax callback. I thought I followed the documentation correctly: http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#ajax_trigger_as
EDIT: One fix is to trigger the submit event through javascript code, but I was really hoping the form api would be able to handle this itself: https://drupal.stackexchange.com/a/34375