I am new to Grails and facing the following problem. I have a popup which displays a form. I want to make an Ajax call to save( def save) the form details and stay in the same popup. But the Grails controller always renders the save.gsp. I believed that the Ajax call would prevent the rendering of the page but it is still happening. I have also tried using formRemote tag. The save.gsp is still getting rendered. I want to view the contents of save.gsp within the popup in updateMe placeholder. Instead the entire page is getting rendered. What is the best solution for this?
my code if given below:(its really raw n messy so pardon me!)
configuration.gsp
<g:formRemote name="myForm" on404="alert('not found!')" update="updateMe"
url="[controller: 'configure', action:'save']">
<div class="form-group">
<label>Company Name</label>
<g:textField name="CompanyName" class="form-control" value="${basicInstance?.CompanyName}" />
</div>
<div class="form-group">
<label>Database</label>
<g:textField name="DB" class="form-control" value="${basicInstance?.DB}" />
</div>
<div class="form-group">
<label>Username to Data base</label>
<g:textField name="DBUserName" class="form-control" value="${basicInstance?.DBUserName}" />
</div>
<div class="form-group">
<label>Password to Data base</label>
<g:textField name="DBPassword" class="form-control" value="${basicInstance?.DBPassword}" />
</div>
<div class="form-group">
<label>URL to Data base</label>
<g:textField name="URL" class="form-control" value="${basicInstance?.URL}" />
</div>
<g:link>
<div class="buttons">
<span class="button" ><g:submitButton name="save" class="btn btn-primary" value="SUBMIT" /></span>
</div>
</g:link>
<div id="updateMe"></div>
</g:formRemote>
configureController
package mdm
import groovy.sql.Sql
class ConfigureController {
static allowedMethods = [save: "POST"]
def configuration={
def basicInstance = new BasicDBInfo()
basicInstance.properties=params
return [basicInstance: basicInstance]
}
def save={
def basicInstance = new BasicDBInfo(params)
if (basicInstance.save(flush: true)) {
flash.message = "${message(code: 'default.created.message', args: [message(code: 'BasicDBInfo.label', default: 'BasicDBInfo'), basicInstance.id])}"
render(view: "save")
}
else {
flash.message = "${message( args: [message(code: 'administrator.label', default: 'soemthing is wrong'), basicInstance.id])}"
}
}
}