John
John

Reputation: 137

Can grails g:formRemote tag update more than one div

Can g:formRemote update more than one div in grails, What would be a viable strategy for updating multiple divs? can anyone explain me this with an example...

Upvotes: 0

Views: 1351

Answers (1)

user800014
user800014

Reputation:

Yes you can control the update of your page. Instead of using the update attribute, use the onSuccess event.

From the docs:

onSuccess (optional) - The JavaScript function to call if successful

Example

View

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

<script type='text/javascript'>
function updateBook(data) {
  //do what you want here
}
</script>

Controller

def show() {
  //TODO: validate if exists and etc..
  def book = Book.get(params.id)
  render book as JSON //send JSON to the client, handling in the updateBook function.  
}

Flow

  • User inform id
  • Ajax request is made
  • g:formRemote will call the javascript function updateBook
  • data will have the JSON that you can parse and do whatever you want (update divs)

Upvotes: 2

Related Questions