How to trigger Ajax forms machinery I'm working on ajaxifying a form which uses Hierarchical Select widget. I need to update a text field based on the value of HS and a couple of other fields. I want to use Drupal forms Ajax API. I followed the http://drupal.org/node/752056. Now the form is updated when user fills in the text fields. But I can't cope with HS. 

I was told http://drupal.org/node/1630186 HS doesn't support regular Drupal #ajax mechanism. I can easily attach the handler to HS update event. So all I need now is to manually trigger Drupal Ajax machinery from my own handler. How it's best to be done? 

I see there is a global Drupal.ajax object but can't figure out how to make use of it.
There is a really simple work around for this.
You can add a button or a hidden input field with an ajax callback and trigger this callback by jQuery.

So declare your button:

$form['my_button'] = array(
   '#type' =&gt; 'button',
   '#ajax' =&gt; array(
     'callback' =&gt; 'my_callback',
     'event' =&gt; 'hs_changed',
   ),
   // hide the button and set a unique id:
   '#prefix' =&gt; "&lt;div style='display:none' id='my_ajax_button'&gt;",
   '#suffix' =&gt; "&lt;/div&gt;"
);


In your javascript you can then easily trigger the event with jQuery.trigger:

jQuery("#my_ajax_button input").trigger('hs_changed');


This will trigger your ajax callback.

http://api.jquery.com/trigger/

http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#ajax