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 show = { [ book : Book.get( params['id'] ) ] }
     def byAuthor = { [ books: Book.findByAuthor( params['author'], params ) ] }
}

Example usages for above controller:

<g:formRemote name="myForm" on404="alert('not found!')" update="updateMe"
              url="[ controller: 'book', action:'show' ]">
    Book Id: <input name="id" type="text"></input>
</g:formRemote>
<div id="updateMe">this div is updated with the result of the show call</div>

<g:formRemote name="myForm" update="updateMe"
              url="[ controller: 'book', action: 'byAuthor', params: [ sort: 'title', order: 'desc' ]]">
    Author: <input name="author" type="text"></input>
</g:formRemote>
<div id="updateMe">this div is updated with the result of the byAuthor call</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/show using a GET if javascript is unavailable:

<g:formRemote name="myForm" update="updateMe" method="GET"
              action="${createLink(controller: 'book', action: 'show')}"
              url="[controller: 'book', action: 'show']">
    Book Id: <input name="id" type="text" />
</g:formRemote>

<div id="updateMe"><!-- this div is updated with the result of the submit --></div>

Description

Attributes

Events

Source

Show Source