开发者

Grails formRemote - how to avoid redirect on multi form?

I have a master controller named Screening. I have build view workflow for this controller (e.g : create, edit, list, show).

On my edit view I'm using Jquery TABS (each tab get content from a template associated to a domain). So to sum up :

Controller (Screening) -> Edit View -> tabs -> Eligibility Inclusion(tab - template/domain)
                                               Eligibility Exclusion(tab - template/domain)
                                               Demographics(tab - template/domain)

So, in my Screening edit view, I'm using formRemote to add template part, ex :

<div id="tabs">
<ul>
   <li><a href="#demographics"><spa开发者_开发问答n>Demographics</span></a></li>
</ul>

<div id="demographics">
<g:formRemote url="[controller:'demographics', action:'update']" update="ajaxMessage" name="demographicsForm">
<span class="onvButton"><g:actionSubmit value="Save" action="update" /></span>
<g:render template="/demographics/editDemographics" model="[demographicsInstance:demographicsInstance]" />
</g:formRemote>
</div> 

I would like to keep validations/saving on Screening view, how can I handle this ?

Actually, if users try save (or if validation failed), they are redirected to demographics controller/view ; how to avoid this ? I don't want users to be redirected.

Is there a best way to handle multi-forms (with template/domain association) in one controller/domain ?


This sounds doing the stuff :

Controller :

def saveRemote = {

    def remoteT1Instance = new RemoteT1(params)
    if (remoteT1Instance.save(flush: true)) {
        flash.message = "${message(code: 'default.created.message', args: [message(code: 'remoteT1.label', default: 'RemoteT1'), remoteT1Instance.id])}"
    }
    else {
        flash.message = null
    }
    render(template: "remote", model: [remoteT1Instance: remoteT1Instance])
}

index.gsp :

<div id="updateArea">
  <g:render template="/remoteT1/remote"/>
</div>

_remote.gsp (template) :

<g:if test="${flash.message}">
            <div class="message">${flash.message}</div>
            </g:if>
            <g:hasErrors bean="${remoteT1Instance}">
            <div class="errors">
                <g:renderErrors bean="${remoteT1Instance}" as="list" />
            </div>
            </g:hasErrors>

            <g:formRemote
              name="editForm"
              url="[controller:'remoteT1', action:'saveRemote']"
              update="updateArea">
                    <table>
                        <tbody>

                            <tr class="prop">
                                <td valign="top" class="name">
                                    <label for="nom"><g:message code="remoteT1.nom.label" default="Nom" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: remoteT1Instance, field: 'nom', 'errors')}">
                                    <g:textField name="nom" value="${remoteT1Instance?.nom}" />
                                </td>
                            </tr>

                            <tr class="prop">
                                <td valign="top" class="name">
                                    <label for="prenom"><g:message code="remoteT1.prenom.label" default="Prenom" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: remoteT1Instance, field: 'prenom', 'errors')}">
                                    <g:textField name="prenom" value="${remoteT1Instance?.prenom}" />
                                </td>
                            </tr>

                            <tr class="prop">
                                <td valign="top" class="name">
                                    <label for="password"><g:message code="remoteT1.password.label" default="Password" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: remoteT1Instance, field: 'password', 'errors')}">
                                    <g:textField name="password" value="${remoteT1Instance?.password}" />
                                </td>
                            </tr>

                            <div id='reply2'></div>

                        </tbody>
                    </table>

                <div class="buttons">
                    <span class="button"><input type="submit" value="Register"/></span>
                </div>
            </g:formRemote>

If I try to use : update="[success:'reply2', failure:'updateArea']" in my g:formRemote, it sound not working, I get 2 div (the old one and new one). I think it's a javascript issue.

Did somebody get something better ?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜