symfony API

JavascriptHelper Functions

You are currently browsing
the website for symfony 1

Visit the Symfony2 website


« Back to API menu

1.1 API OpenSearch

Packages

You are currently browsing the symfony API for the 1.1 version. Switch to:
This version of symfony is not maintained anymore.
If some of your projects still use this version, consider upgrading as soon as possible.

JavascriptHelper.

Function Summary

Function Details

  • button_to_function () Browse code

    Returns a button that'll trigger a javascript function using the

    onclick handler and return false after the fact.

    Examples:

  • button_to_remote () Browse code

    Returns an html button to a remote action defined by 'url' (using the

    'url_for()' format) that's called in the background using XMLHttpRequest.

    See link_to_remote() for details.

  • draggable_element () Browse code

    Makes the element with the DOM ID specified by '$element_id' draggable.


    Example:
    'revert' => true,
    )) ?>

    You can change the behaviour with various options, see
    http://script.aculo.us for more documentation.

  • drop_receiving_element () Browse code

    Makes the element with the DOM ID specified by '$element_id' receive

    dropped draggable elements (created by 'draggable_element()') and make an AJAX call.
    By default, the action called gets the DOM ID of the element as parameter.

    Example:
    'url' => 'cart/add',
    )) ?>

    You can change the behaviour with various options, see
    http://script.aculo.us for more documentation.

  • end_if_javascript () Browse code

    Mark the end of a block that should only be shown in the browser if JavaScript

    is switched on.

  • evaluate_remote_response () Browse code

    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.

  • form_remote_tag () Browse code

    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').
    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:
    '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').

  • get_ajax_options () Browse code

  • get_callbacks () Browse code

  • if_javascript () Browse code

    Mark the start of a block that should only be shown in the browser if JavaScript

    is switched on.

  • (string) input_auto_complete_tag (, , , ) Browse code

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

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

  • (string) input_in_place_editor_tag (, , ) Browse code

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

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

  • javascript_cdata_section () Browse code

  • javascript_tag () Browse code

    Returns a JavaScript tag with the '$content' inside.

    Example:

    =>

  • link_to_function () Browse code

    Returns a link that'll trigger a javascript function using the

    onclick handler and return false after the fact.

    Examples:

    'Really?')) ?>

  • link_to_remote () Browse code

    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'.
    Usually, the result would be a partial prepared by the controller with
    either 'render_partial()'.

    Examples:
    'update' => 'posts',
    'url' => 'destroy?id='.$post.id,
    )) ?>
    '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:
    '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:
    '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:
    '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.

  • observe_field () Browse code

    Observes the field with the DOM ID specified by '$field_id' 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().

  • observe_form () Browse code

    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.

  • periodically_call_remote () Browse code

    Periodically calls the specified url ('url') every 'frequency' 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()'.

  • remote_function () Browse code

    Returns the javascript needed for a remote function.

    Takes the same arguments as 'link_to_remote()'.

    Example:

  • sortable_element () Browse code

    Makes the elements with the DOM ID specified by '$element_id' sortable

    by drag-and-drop and if an 'url' is specified make an AJAX call whenever
    the sort order has changed. By default, the action called gets the
    serialized sortable element as parameters.

    Example:
    '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.

  • submit_image_to_remote () Browse code

    Returns a image submit 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()'.

  • submit_to_remote () Browse code

    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()'.

  • update_element_function () Browse code

    Returns a Javascript function (or expression) that will update a DOM element '$element_id'

    according to the '$options' 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:
    update_element_function('products', array(
    'position' => 'bottom',
    'content' => "

    New product!

    ",
    ))
    ) ?>

    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
    'url' => '@buy',
    'complete' => evaluate_remote_response()
    )) ?>
    all the inputs here...

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

    # Returning view
    'action' => 'update',
    'position' => 'bottom',
    'content' => '

    New Product: '.$product->getName().'

    ',
    )) ?>

  • visual_effect () Browse code

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

    visual effects.

    Example:
    '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():

    ...
    '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.

  • (string) _array_or_string_for_javascript () Browse code

    converts the given PHP array or string to the corresponding javascript array or string.

    javascript strings need to be single quoted.

    returns javascript string or array equivalent

  • (string) _auto_complete_field (, , ) Browse code

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

    returns javascript tag for Ajax.Autocompleter

  • (string) _boolean_for_javascript () Browse code

    converts the given PHP boolean to the corresponding javascript boolean.

    booleans need to be true or false (php will print 1 or nothing).

    returns javascript boolean equivalent

  • _build_callbacks () Browse code

  • _build_observer () Browse code

  • _in_place_editor () Browse code

  • _options_for_ajax () Browse code

  • _options_for_javascript () Browse code