Jamie
Jamie

Reputation: 73

Altering submit button in Grails

I'm working on a Grails application and as you can see from the screenshot below, at the bottom of my create page I have two submit buttons, the one on the left creates and saves the instance and takes me to the show page of the instance I have just created.

The submit button on the right does exactly the same thing however I now want that button to save/create the instance but stay on this same (create) page and not redirect me to show.gsp with the fields still filled with the data previously entered. Is this possible?

Here is the code for the two buttons at the bottom of create.gsp

<g:submitButton name="create" class="save" value="${message(code: 'default.button.create.label',      default: 'Create')}" />
<g:submitButton name="create" class="save" value="${message(code: 'default.button.create.label', default: 'Create')}" />

Buttons

Upvotes: 0

Views: 394

Answers (1)

injecteer
injecteer

Reputation: 20699

instead of <g:submitButton> you should use:

<g:actionSubmit value="${message(default:'Create')}" action="create" />
<g:actionSubmit value="${message(default:'Create and Stay')}" action="createAndStay" />

in the corresponding controler actions you decide wether you redirect to list or to create actions

Upvotes: 3

Related Questions