views:

66

answers:

1

Hi,

Assume i have a book entity with an isbn field. When entered a isbn number, i want 2 fields to be updated: title and author.

My controller looks like this:

def ajaxGetBook = {
        def book = Book.findByIsbn(params.isbn)
        if(book==null) book = new Book()
        render book as JSON
    }

So my call works, and i get a full JSON Book. Now i would like to update 2 texfields by the update attribute

 <g:remoteField action="ajaxGetBook" update="title"  name="isbn" value="${bookInstance?.book?.isbn}" paramName="isbn"/>

Now the title field gets updated with the full book object, so that doesn't work.

Is it possible to update field title with only the JSON book.title?

Is it possible to update more fields at once?

I could render book.title as JSON but that works for only one field.

Thank you

A: 

Well, the g:remoteField tag is explicitly for one field, so you can't use it to update more than one. So, you're left with 2 easy choices:

  1. Use 2 g:remoteField calls... this isn't a bad option, as they would happen in near parallel, as they are Async calls.

  2. Roll your own Ajax. use g:remoteFunction instead, and have the JS function that you place in the "success" attribute take your book, and update the appropriate HTML fields.

Bill James