Reputation: 549
I am trying to call a function once a selection is made in the drop down menu. Here is my code for the drop down menu in my list.gsp for the 'Code' domain class:
<td><g:select name="data" from="${codeInstance.datas.language}"
onchange="${remoteFunction(action: 'translationById')}"/>
</td>
And here is the function I am trying to call. This is in my CodeController:
def translationById = {
println "Fine"
//println params;
}
I am just trying to print out "Fine" so I know that the function was called, but "Fine" never gets printed. Why is the function not getting called?
Upvotes: 1
Views: 1203
Reputation: 3407
Instead of using a closure, use a method, like:
def translationById() {
println "Fine"
//println params;
}
Also, use some browser debugger like firebug or similar to see if error message is being displayed.
What happens if you put an alert inside the onchange event instead of a remoteFunction? If the alert is displayed, then I think your problem is with the prototype library. Add the prototype library to your header. Like <g:javascript library="prototype" />
.
Upvotes: 1
Reputation: 1461
The syntax looks fine to me. Try to make sure that your 'codeInstance' and 'datas' are not null. Also, try and pass in the controller name like this:
remoteFunction(action: 'translationById', controller: 'code')
The new norm in grails is to use methods instead of closures:
def translationById(){
println "fine"
}
Upvotes: 0