I have a button that updates a tag like fieldset or td to show the rendered template:
<td id="tdBtn"><g:submitToRemote name="showFieldSet" value="Edit" update="fieldSet" action="setPwdTxtVisible" onComplete="hideBtn(3)" /></td>
<fieldset id="fieldSet">
<-- this will be the section where the template will be rendered upon btn click name="showFieldSet" -->
</fieldset>
the action:
def setPwdTxtVisible=
{
def employeeId= params.employeeId
MySession session = MySession.getMySession(request, params.employeeId)
session.profileInstance.isEditPwd = true
render(template:"/layouts/passwordProfile")
}
Is there a way to do the update inside a def method instead of in a button? The thing is when the validate fails upon saving the data, the page is reloaded and the updated td comes back to no rendered template again. I want to update the td inside the catch (in a try catch statement in SAVE method)so that the template will still be there. like coding it this way: And how do I access the td in the frist place not using javascript? Is this possible?
def setPwdTxtVisible=
{
def employeeId= params.employeeId
MySession session = MySession.getMySession(request, params.employeeId)
session.profileInstance.isEditPwd = true
render(template:"/layouts/passwordProfile")
update fieldset //<<------
}
You can’t do this without javascript. The controller does not have access to the DOM.
Modify your controller action so that it returns a failure or success message, then you can use a map in the update method – update=”[success: ‘message’, failure: ‘error’]”
If you do this, it basically says that if your AJAX call failed, it renders an error in the client side on the div called error.
You can also control the flow of error messages via http status messages, so in your submitToRemote method, you can add a on501=”error” , which updates the error div with the contents of your 501 or use a specific server action.
http://grails.org/doc/latest/ref/Tags/submitToRemote.html
Your controllers should never manipulate DOM elements.