formRemote

Purpose

Creates a form tag that uses a remote uri to execute an ajax call serializing the form elements falling back to a normal form submit if javascript is not supported.

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:formRemote name="myForm" on404="alert('not found!')" update="updateMe" url="[action:'show']">
    Login: <input name="login" type="text"></input>
</g:formRemote>
<div id="updateMe">this div is updated by the form</div>

<g:formRemote name="myForm" update="updateMe"
              url="[ controller: 'book', action: 'list', params: [ sort: 'title', order: 'desc' ]]">
    Login: <input name="login" type="text"></input>
</g:formRemote>
<div id="updateMe">this div is updated by the form</div>

You can override both the form method and action to use when javascript is unavailable by providing method and action attributes. This example will submit the form to /<context>/book/oldList using a GET if javascript is unavailable:

<g:formRemote name="myForm" method="GET" action="${createLink(controller: 'book', action: 'oldList')}"
              url="[ controller: 'book', action: 'list', params: [ sort: 'title', order: 'desc' ]]">
    Login: <input name="login" type="text"></input>
</g:formRemote>

Description

Attributes

Events

Source

Show Source