(Quick Reference)

submitToRemote

Purpose

Creates a button that submits the containing form as a remote Ajax call, serializing the fields into parameters.

Examples

Example controller for an application called "shop":

class BookController {

def list() { [books: Book.list(params)] }

def show() { [book: Book.get(params.id)] } }

Example usages for above controller:

<g:form action="show">
    Login: <input name="login" type="text" />
    <g:submitToRemote update="updateMe" />
</g:form>

<div id="updateMe">this div will be updated with the form submit response</div>

Description

This tag creates a submit button that fires an AJAX request when it is pressed. The exact Javascript used to fire off the AJAX request depends on which Javascript library is used. This tag also requires the use of either the <g:javascript/> or <g:setProvider/> tags. See the AJAX section of the user guide to find out more.

Attributes

  • url - The url to submit to, either a map contraining keys for the action, controller and id or a string value
  • update (optional) - Either a Map containing the elements to update for 'success' or 'failure' states, or a string with the element id to update, in which case failure events would be ignored
  • before (optional) - The JavaScript function to call before the remote function call. A semi-colon is automatically added so you don't have to provide one yourself in this string.
  • after (optional) - The JavaScript function to call after the remote function call. A semi-colon is automatically added so you don't have to provide one yourself in this string.
  • asynchronous (optional) - Whether to do the call asynchronously (defaults to true)
  • method (optional) - The method to use the execute the call (defaults to POST)

Events

  • onSuccess (optional) - The JavaScript function to call if successful
  • onFailure (optional) - The JavaScript function to call if the call fails
  • on_ERROR_CODE (optional) - The JavaScript function to call to handle the specified error code (eg on404="alert('not found!')")
  • onUninitialized (optional) - The JavaScript function to call if Ajax fails to initialise
  • onLoading (optional) - The JavaScript function to call when the remote function loads the response
  • onLoaded (optional) - The JavaScript function to call when the remote function completes loading the response
  • onComplete (optional) - The JavaScript function to call when the remote function completes, including any updates

Source