I want to call a JS function either by the "onload()" function after a template has been rendered, or through the "onSuccess()" callback in the g:formRemote tag. Inside my main GSP I have the following. This code makes a callback to a controller and sets up the model to be passed into the template.
GSP:
<g:formRemote name="ptoReport" url="[controller:'Report', action:'ptoBarChart']" update="barChartDiv">
<g:submitButton name="pto" value="PTO" class="btn btn-primary"/>
</g:formRemote>
<div id="barChartDiv">
<g:render template="barChart"/>
</div>
My controller code looks like so:
Controller:
def ptoBarChart(){
Map usersAndPTO = timesheetService.getPTOForAllUsers()
render(template: 'barChart', model:[points: usersAndPTO])
}
I want to call a JS function immediately after the template has loaded, but the trick is to pass in the "usersAndPTO" map into the JS function. I have tried adding "onLoad="barChart(${points})"" to the rendered template, but it never gets called. And adding the "onSuccess="barChart(data)"" to the g:formRemote results in me passing the GSP code for the template to the JS function.
Any help greatly appreciated.