symfony API

JavascriptHelper Functions

« Back to API menu

action

addon

cache

config

controller

countable

database

debug

exception

filter

generator

helper

i18n

log

request

response

storage

test

user

util

validator

view

You are currently browsing the symfony API for the 1.0 version. Switch to:

JavascriptHelper.

Function Summary

  • _build_observer($klass, $name, $options = array())
  • string input_auto_complete_tag($name, $value, $url, $tag_options = array(), $completion_options = array())
    wrapper for script.aculo.us/prototype Ajax.Autocompleter.
  • string _auto_complete_field($field_id, $url, $options = array())
    wrapper for script.aculo.us/prototype Ajax.Autocompleter.
  • button_to_function($name, $function, $html_options = array())
    Returns a button that'll trigger a javascript function using the onclick handler and return false after the fact.
  • periodically_call_remote($options = array())
    Periodically calls the specified url ('url') every 'frequency' seconds (default is 10).
  • observe_field($field_id, $options = array())
    Observes the field with the DOM ID specified by '$field_id' and makes an AJAX call when its contents have changed.
  • _method_option_to_s($method)
  • draggable_element($element_id, $options = array())
    Makes the element with the DOM ID specified by '$element_id' draggable.
  • javascript_cdata_section($content)
  • remote_function($options)
    Returns the javascript needed for a remote function.
  • get_callbacks()
  • link_to_function($name, $function, $html_options = array())
    Returns a link that'll trigger a javascript function using the onclick handler and return false after the fact.
  • form_remote_tag($options = array(), $options_html = array())
    Returns a form tag that will submit using XMLHttpRequest in the background instead of the regular reloading POST arrangement. Even though it's using JavaScript to serialize the form elements, the form submission will work just like a regular submission as viewed by the receiving side (all elements available in 'params').
  • _array_or_string_for_javascript($option)
  • sortable_element($element_id, $options = array())
    Makes the elements with the DOM ID specified by '$element_id' sortable by drag-and-drop and make an AJAX call whenever the sort order has changed. By default, the action called gets the serialized sortable element as parameters.
  • get_ajax_options()
  • drop_receiving_element($element_id, $options = array())
    Makes the element with the DOM ID specified by '$element_id' receive dropped draggable elements (created by 'draggable_element()') and make an AJAX call.
  • submit_to_remote($name, $value, $options = array(), $options_html = array())
    Returns a button input tag that will submit form using XMLHttpRequest in the background instead of regular reloading POST arrangement. The '$options' argument is the same as in 'form_remote_tag()'.
  • if_javascript()
    Mark the start of a block that should only be shown in the browser if JavaScript is switched on.
  • link_to_remote($name, $options = array(), $html_options = array())
    Returns a link to a remote action defined by 'url' (using the 'url_for()' format) that's called in the background using XMLHttpRequest. The result of that request can then be inserted into a DOM object whose id can be specified with 'update'.
  • _build_callbacks($options)
  • _options_for_ajax($options)
  • _options_for_javascript($options)
  • end_if_javascript()
    Mark the end of a block that should only be shown in the browser if JavaScript is switched on.
  • visual_effect($name, $element_id = false, $js_options = array())
    Returns a JavaScript snippet to be used on the AJAX callbacks for starting visual effects.
  • observe_form($form_id, $options = array())
    Like 'observe_field()', but operates on an entire form identified by the DOM ID '$form_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.
  • javascript_tag($content)
    Returns a JavaScript tag with the '$content' inside.
  • string input_in_place_editor_tag($name, $url, $editor_options = array())
    wrapper for script.aculo.us/prototype Ajax.InPlaceEditor.
  • _in_place_editor($field_id, $url, $options = array())
  • evaluate_remote_response()
    Returns 'eval(request.responseText)', which is the Javascript function that 'form_remote_tag()' can call in 'complete' to evaluate a multiple update return document using 'update_element_function()' calls.
  • update_element_function($element_id, $options = array())
    Returns a Javascript function (or expression) that will update a DOM element '$element_id' according to the '$options' passed.
  • button_to_remote($name, $options = array(), $html_options = array())
    Returns an html button to a remote action defined by 'url' (using the 'url_for()' format) that's called in the background using XMLHttpRequest.

Function Details

  • _build_observer ($klass, $name, $options = array())

  • (string) input_auto_complete_tag ($name, $value, $url, $tag_options = array(), $completion_options = array())

    $name name value of input field
    $value default value for input field
    $url input tag options. (size, autocomplete, etc...)
    $tag_options completion options. (use_style, etc...)

    wrapper for script.aculo.us/prototype Ajax.Autocompleter.

    returns input field tag, div for completion results, and auto complete javascript tags

  • (string) _auto_complete_field ($field_id, $url, $options = array())

    $field_id id value of input field
    $url url of module/action to execute for autocompletion
    $options completion options

    wrapper for script.aculo.us/prototype Ajax.Autocompleter.

    returns javascript tag for Ajax.Autocompleter

  • button_to_function ($name, $function, $html_options = array())

    Returns a button that'll trigger a javascript function using the onclick handler and return false after the fact.

    Examples: <?php echo button_to_function('Greeting', "alert('Hello world!')") ?>

  • periodically_call_remote ($options = array())

    Periodically calls the specified url (&apos;url&apos;) every &apos;frequency&apos; seconds (default is 10).

    Usually used to update a specified div ('update') with the results of the remote call. The options for specifying the target with 'url' and defining callbacks is the same as 'link_to_remote()'.

  • observe_field ($field_id, $options = array())

    Observes the field with the DOM ID specified by &apos;$field_id&apos; and makes an AJAX call when its contents have changed.

    Required '$options' are: 'url' 'url_for()'-style options for the action to call when the field has changed.
    Additional options are: 'frequency' The frequency (in seconds) at which changes to this field will be detected. Not setting this option at all or to a value equal to or less than zero will use event based observation instead of time based observation. 'update' Specifies the DOM ID of the element whose innerHTML should be updated with the XMLHttpRequest response text. 'with' A JavaScript expression specifying the parameters for the XMLHttpRequest. This defaults to 'value', which in the evaluated context refers to the new field value.
    Additionally, you may specify any of the options documented in link_to_remote().

  • _method_option_to_s ($method)

  • draggable_element ($element_id, $options = array())

    Makes the element with the DOM ID specified by &apos;$element_id&apos; draggable.

    Example: <?php echo draggable_element('my_image', array( 'revert' => true, )) ?>
    You can change the behaviour with various options, see http://script.aculo.us for more documentation.

  • javascript_cdata_section ($content)

  • remote_function ($options)

    Returns the javascript needed for a remote function.

    Takes the same arguments as 'link_to_remote()'.
    Example: <select id="options" onchange="<?php echo remote_function(array('update' => 'options', 'url' => '@update_options')) ?>"> <option value="0">Hello</option> <option value="1">World</option> </select>

  • get_callbacks ()

  • link_to_function ($name, $function, $html_options = array())

    Returns a link that&apos;ll trigger a javascript function using the onclick handler and return false after the fact.

    Examples: <?php echo link_to_function('Greeting', "alert('Hello world!')") ?> <?php echo link_to_function(image_tag('delete'), "if confirm('Really?'){ do_delete(); }") ?>

  • form_remote_tag ($options = array(), $options_html = array())

    Returns a form tag that will submit using XMLHttpRequest in the background instead of the regular reloading POST arrangement. Even though it&apos;s using JavaScript to serialize the form elements, the form submission will work just like a regular submission as viewed by the receiving side (all elements available in &apos;params&apos;).

    The options for specifying the target with 'url' and defining callbacks are the same as 'link_to_remote()'.
    A "fall-through" target for browsers that don't do JavaScript can be specified with the 'action'/'method' options on '$options_html'
    Example: <?php echo form_remote_tag(array( 'url' => '@tag_add', 'update' => 'question_tags', 'loading' => "Element.show('indicator'); \$('tag').value = ''", 'complete' => "Element.hide('indicator');".visual_effect('highlight', 'question_tags'), )) ?>
    The hash passed as a second argument is equivalent to the options (2nd) argument in the form_tag() helper.
    By default the fall-through action is the same as the one specified in the 'url' (and the default method is 'post').

  • _array_or_string_for_javascript ($option)

  • sortable_element ($element_id, $options = array())

    Makes the elements with the DOM ID specified by &apos;$element_id&apos; sortable by drag-and-drop and make an AJAX call whenever the sort order has changed. By default, the action called gets the serialized sortable element as parameters.

    Example: <php echo sortable_element($my_list, array( 'url' => '@order', )) ?>
    In the example, the action gets a '$my_list' array parameter containing the values of the ids of elements the sortable consists of, in the current order.
    You can change the behaviour with various options, see http://script.aculo.us for more documentation.

  • get_ajax_options ()

  • drop_receiving_element ($element_id, $options = array())

    Makes the element with the DOM ID specified by &apos;$element_id&apos; receive dropped draggable elements (created by &apos;draggable_element()&apos;) and make an AJAX call.

    By default, the action called gets the DOM ID of the element as parameter.
    Example: <?php drop_receiving_element('my_cart', array( 'url' => 'cart/add', )) ?>
    You can change the behaviour with various options, see http://script.aculo.us for more documentation.

  • submit_to_remote ($name, $value, $options = array(), $options_html = array())

    Returns a button input tag that will submit form using XMLHttpRequest in the background instead of regular reloading POST arrangement. The &apos;$options&apos; argument is the same as in &apos;form_remote_tag()&apos;.

  • if_javascript ()

    Mark the start of a block that should only be shown in the browser if JavaScript is switched on.

  • link_to_remote ($name, $options = array(), $html_options = array())

    Returns a link to a remote action defined by &apos;url&apos; (using the &apos;url_for()&apos; format) that&apos;s called in the background using XMLHttpRequest. The result of that request can then be inserted into a DOM object whose id can be specified with &apos;update&apos;.

    Usually, the result would be a partial prepared by the controller with either 'render_partial()'.
    Examples: <?php echo link_to_remote('Delete this post'), array( 'update' => 'posts', 'url' => 'destroy?id='.$post.id, )) ?> <?php echo link_to_remote(image_tag('refresh'), array( 'update' => 'emails', 'url' => '@list_emails', )) ?>
    You can also specify a hash for 'update' to allow for easy redirection of output to an other DOM element if a server-side error occurs:
    Example: <?php echo link_to_remote('Delete this post', array( 'update' => array('success' => 'posts', 'failure' => 'error'), 'url' => 'destroy?id='.$post.id, )) ?>
    Optionally, you can use the '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'.
    Example: <?php echo link_to_remote($word, array( 'url' => '@undo?n='.$word_counter, 'complete' => 'undoRequestCompleted(request)' )) ?>
    The callbacks that may be specified are (in order):
    'loading' Called when the remote document is being loaded with data by the browser. 'loaded' Called when the browser has finished loading the remote document. 'interactive' Called when the user can interact with the remote document, even though it has not finished loading. 'success' Called when the XMLHttpRequest is completed, and the HTTP status code is in the 2XX range. 'failure' Called when the XMLHttpRequest is completed, and the HTTP status code is not in the 2XX range. 'complete' Called when the XMLHttpRequest is complete (fires after success/failure if they are present).,
    You can further refine 'success' and 'failure' by adding additional callbacks for specific status codes:
    Example: <?php echo link_to_remote($word, array( 'url' => '@rule', '404' => "alert('Not found...? Wrong URL...?')", 'failure' => "alert('HTTP Error ' + request.status + '!')", )) ?>
    A status code callback overrides the success/failure handlers if present.
    If you for some reason or another need synchronous processing (that'll block the browser while the request is happening), you can specify 'type' => 'synchronous'.
    You can customize further browser side call logic by passing in JavaScript code snippets via some optional parameters. In their order of use these are:
    'confirm' Adds confirmation dialog. 'condition' Perform remote request conditionally by this expression. Use this to describe browser-side conditions when request should not be initiated. 'before' Called before request is initiated. 'after' Called immediately after request was initiated and before 'loading'. 'submit' Specifies the DOM element ID that's used as the parent of the form elements. By default this is the current form, but it could just as well be the ID of a table row or any other DOM element.

  • _build_callbacks ($options)

  • _options_for_ajax ($options)

  • _options_for_javascript ($options)

  • end_if_javascript ()

    Mark the end of a block that should only be shown in the browser if JavaScript is switched on.

  • visual_effect ($name, $element_id = false, $js_options = array())

    Returns a JavaScript snippet to be used on the AJAX callbacks for starting visual effects.

    Example: <?php echo link_to_remote('Reload', array( 'update' => 'posts', 'url' => '@reload', 'complete => visual_effect('highlight', 'posts', array('duration' => 0.5 )), )) ?>
    If no '$element_id' is given, it assumes "element" which should be a local variable in the generated JavaScript execution context. This can be used for example with drop_receiving_element():
    <?php echo drop_receving_element( ..., array( ... 'loading' => visual_effect('fade'), )) ?>
    This would fade the element that was dropped on the drop receiving element.
    You can change the behaviour with various options, see http://script.aculo.us for more documentation.

  • observe_form ($form_id, $options = array())

    Like &apos;observe_field()&apos;, but operates on an entire form identified by the DOM ID &apos;$form_id&apos;. &apos;$options&apos; are the same as &apos;observe_field()&apos;, except the default value of the &apos;with&apos; option evaluates to the serialized (request string) value of the form.

  • javascript_tag ($content)

    Returns a JavaScript tag with the &apos;$content&apos; inside.

    Example: <?php echo javascript_tag("alert('All is good')") ?> => <script type="text/javascript">alert('All is good')</script>

  • (string) input_in_place_editor_tag ($name, $url, $editor_options = array())

    $name name id of field that can be edited
    $url url of module/action to be called when ok is clicked
    $editor_options editor tag options. (rows, cols, highlightcolor, highlightendcolor, etc...)

    wrapper for script.aculo.us/prototype Ajax.InPlaceEditor.

    returns javascript to manipulate the id field to allow click and edit functionality

  • _in_place_editor ($field_id, $url, $options = array())

  • evaluate_remote_response ()

    Returns &apos;eval(request.responseText)&apos;, which is the Javascript function that &apos;form_remote_tag()&apos; can call in &apos;complete&apos; to evaluate a multiple update return document using &apos;update_element_function()&apos; calls.

  • update_element_function ($element_id, $options = array())

    Returns a Javascript function (or expression) that will update a DOM element &apos;$element_id&apos; according to the &apos;$options&apos; passed.

    Possible '$options' are: 'content' The content to use for updating. Can be left out if using block, see example. 'action' Valid options are 'update' (assumed by default), 'empty', 'remove' 'position' If the 'action' is 'update', you can optionally specify one of the following positions: 'before', 'top', 'bottom', 'after'.
    Example: <?php echo javascript_tag( update_element_function('products', array( 'position' => 'bottom', 'content' => "<p>New product!</p>", )) ) ?>
    This method can also be used in combination with remote method call where the result is evaluated afterwards to cause multiple updates on a page.
    Example:


    • Calling view



    <?php echo form_remote_tag(array( 'url' => '@buy', 'complete' => evaluate_remote_response() )) ?> all the inputs here...

    • Target action



    public function executeBuy() { $this->product = ProductPeer::retrieveByPk(1); }

    • Returning view



    <php echo update_element_function('cart', array( 'action' => 'update', 'position' => 'bottom', 'content' => '<p>New Product: '.$product->getName().'</p>', )) ?>

  • button_to_remote ($name, $options = array(), $html_options = array())

    Returns an html button to a remote action defined by &apos;url&apos; (using the &apos;url_for()&apos; format) that&apos;s called in the background using XMLHttpRequest.

    See link_to_remote() for details.