/view/lib/helpers/ajax_helper.phpAjax helpers
Set of functions for working with javascript and Prototype functions, including functionality to call remote methods using Ajax.
auto_complete_field
($id, $options = array())
escape_javascript
($javascript)
Escape carrier returns and single and double quotes for javascript code
form_remote_tag
($options = array())
Returns a form tag that will submit using XMLHttpRequest in the background
in_place_editor
($field_id, $options = array())
in_place_editor_field
($object_name, $method, $object, $tag_options = array(), $editor_options = array())
javascript_tag
($code)
Returns a javascript tag with the $code inside
link_to_function
($content, $function, $html_options = array())
Returns a link that will trigger a javascript function using the onclick handler
Example :
link_to_function("Hello", "alert('Hello world !')");
Produces:
<a onclick="alert('Hello world !'); return false;" href="#">Hello</a>
link_to_remote
($content, $options = array(), $html_options = array())
Returns a link to a remote action whose url is defined by $options['url'].
This action is called using xmlHttpRequest and the response can be inserted into the page, in a DOM object whose id is specified by $options['update']. Usually, the response would be a partial prepared by the controller with either render_partial() or render_partial_collection().
Example :
link_to_remote("Delete this post", array('update' => 'posts',
'url' => array('action' => 'destroy', 'id' => $this->post->id)));
You can also specify an array for $options['update'] to allow for easy redirection of output to an other DOM element if a server-side error occurs.
Example :
link_to_remote("Delete this post", array('url' => array('action' => 'destroy', 'id' => $this->post->id),
'update' => array('success' => 'posts', 'failure' => 'errors')));
Optionally, you can use the $options['position'] parameter to influence how the target DOM element is updated. It must be one of 'before', 'top', 'bottom', or 'after'.
By default, these remote requests are processed asynchronous during which various JavaScript callbacks can be triggered (for progress indicators and the likes). All callbacks get access to the request object, which holds the underlying XMLHttpRequest. To access the server response, use request.responseText, to find out the HTTP status, use request.status.
The callbacks that may be specified are (in order):
Example :
link_to_remote("Delete this post", array('url' => array('action' => 'destroy', 'id' => $this->post->id),
'update' => 'posts', 'failure' => "alert('HTTP Error ' + request.status + '!')"));
observe_field
($id, $options = array())
Observes the field with the DOM ID specified by $id and makes an Ajax call when its contents have changed.
Required options are either of:
Additional options are:
Additionally, you may specify any of the options documented in link_to_remote.
observe_form
($id, $options = array())
Like observe_field, but operates on an entire form identified by the DOM ID $id.
Options are the same as observe_field, except the default value of the with option evaluates to the serialized (request string) value of the form.
remote_function
($options)
Returns the JavaScript needed for a remote function. Takes the same arguments as link_to_remote.
Example :
<select id="options" onchange="<?= remote_function(array('update' => "options", 'url' => array('action' => 'update_options'))); ? >">
<option value="0">Hello</option>
<option value="1">World</option>
</select>
text_field_with_auto_complete
($object_name, $method, $object, $tag_options = array(), $completion_options = array())
Documentation generated on Wed, 24 Jan 2007 15:00:05 +0100 by phpDocumentor 1.3.0RC4