Reputation: 81
It seems that with g:formRemote and g:submitToRemote, I can only specify one update target div. What would be a viable strategy for updating multiple divs?
Upvotes: 2
Views: 3546
Reputation: 252
From the grails doc for g:formremote, http://grails.org/doc/2.2.0/ref/Tags/formRemote.html , you can use the onSuccess callback to define a js function for a succesfull submit, so you can update all your target elements within that function, otherwise making an ajax call yourself also is a good option.
Upvotes: 0
Reputation: 11
there is asolution to this grails problem, you can use taconite, where taconite allows to update muliple elements with one single ajax call
http://malsup.com/jquery/taconite/
and there is another solution posted at someone's blog, but my reputation does only allow me to post one link here on stackoverflow!!!
so i give the title of the blog post "Updating multiple page elements with Grails and Ajax"
Upvotes: 1
Reputation: 5165
You could instead of using update, use onSuccess and parse the response and update the elements you need to update like this:
<g:formRemote name='loginForm' url="[action:'login']"
onSuccess='loginOK(e)' >
<!-- form fields -->
</g:formRemote>
<g:javascript>
function loginOK( resp ) {
// parse the resp.responseText and update
}
</g:javascript>
Or you could just use jQuery and roll your own like the previous answer suggests.
If you want to update one element based on success vs another on failure you can use a map like this:
<g:formRemote name='loginForm' url="[action:'login']" update="[success:'message',failure:'error']">
Upvotes: 1
Reputation: 14738
if you want to stick with using the g:formRemote tags to perform your ajax, it might not be possible. Why not write some jQuery, and roll a custom ajax update? it couldnt be easier!
Upvotes: 1