JackRackham
JackRackham

Reputation: 61

Grails RemoteForm, Ajax doesn't work

I'm new on Grails and I have some troubles with Ajax (so I could have missed something). On my main gsp I want a select box, that, when I click on its options, makes appear another field on the same page to select other things. As the content in the second part is dynamic, I need somme Ajax. Anyway I haven't succeed yet. Here is my code :

main.gsp

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="layout" content="main" />
    <title>Sample title</title>
    <g:javascript library="jquery"/>
  </head>
  <body>
    <h1>Selection de l'email</h1>
    <div class="dialog">
        <g:select name="selectTemplate"
                  from="${templateCategories}"
                  value="category"
                  noSelection="['':'--- choisissez un modèle ---']"
                  onchange="${remoteFunction(
                      controller:"email"
                      action:"printTestTemplate"
                      update:"listTemplates"
                      params:'\'category=\'+this.value'
                      )}"
                  />
          <div id="listTemplates">RRR</div>
      </div>
   </body>
</html>

EmailController

def printTestTemplate = {
    println params.category //doesn't print anything
    println "YEAAAAAAAAAH"  //the same
    render(view:"formSelectTemplate", model:[templates:EmailTemplate.findByCategory(params.templateCategory)])
}

formSelectTemplate.gsp

<h1>YOUHOUUU !</h1>

I've both tried to call a view or template (by renaming the gsp of course), but nothing worked. Nevertheless I don't understand, I followed the official doc. Notice that the HTML result creates no event on the select box, and that Firebug tells me there is no 404. So I must have missed something in the creation of the box.

select result in HTML :

<select id="selectTemplate" name="selectTemplate">  
    <option value="Refus">Refus</option>  
    <option value="Informations complémentaires">Informations complémentaires</option>  
</select>  

Upvotes: 2

Views: 795

Answers (1)

Antoine
Antoine

Reputation: 5198

Did you forget comas between the arguments of your remoteFunction call ? like this:

onchange="${remoteFunction(controller:"email",
                           action:"printTestTemplate",
                           update:"listTemplates",
                           params:'\'category=\'+this.value' )}"

Upvotes: 1

Related Questions