How to use #ajax trigger_as? 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' =&gt; 'submit',
  '#value' =&gt; t('Add another item'),
  '#attributes' =&gt; array('class' =&gt; array('add-more-submit')),
  '#submit' =&gt; array('field_add_more_submit'),
  '#name' =&gt; 'result_fields_add_more',
  '#ajax' =&gt; array(
    'callback' =&gt; '__update_fields',
    'wrapper' =&gt; 'example-wrapper',
    'effect' =&gt; 'fade',
  ),
);

$form['add_more_link'] = array(
  '#type' =&gt; 'link',
  '#title' =&gt; t('add'),
  '#href' =&gt; '#',
  '#process' =&gt; array('ajax_process_form'),
  '#ajax' =&gt; array(
    'callback' =&gt; '_update_fields',
    'wrapper' =&gt; 'example-wrapper',
    'effect' =&gt; 'fade',
    'event' =&gt; 'click',
    'trigger_as' =&gt; array(
      'name' =&gt; 'result_fields_add_more',
      'value' =&gt; 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
No support for links, but for what its worth heres a working snippet that uses a select.

When the select changes it triggers the submit buttons callback.
Note, you still have to define the callback on the select box as ajax.inc assumes all ajax enabled elements have one.



&lt;?php

  $submit_name = 'product-submit-' . $node-&gt;nid;
  $form['product_id'] = array(
    '#type' =&gt; 'select',
    '#options' =&gt; $options,
    '#ajax' =&gt; array(
      'wrapper' =&gt; 'my-form-wrapper',
      'callback' =&gt; 'product_change_callback',
      'trigger_as' =&gt; array(
        'name' =&gt; $submit_name,
      ),
    ),
  );

  $form['submit'] = array(
    '#name' =&gt; $submit_name,
    '#type' =&gt; 'submit',
    '#value' =&gt; t('Submit'),
    '#ajax' =&gt; array(
      'callback' =&gt; 'product_change_callback',
    ),
  );
?&gt;