Grails formRemote - 如何避免在多表单上重定向?

发布于 2024-10-30 18:54:22 字数 1187 浏览 0 评论 0原文

我有一个名为 Screening 的主控制器。 我有这个控制器的构建视图工作流程(例如:创建、编辑、列表、显示)。

在我的编辑视图中,我使用 Jquery TABS(每个选项卡从与域关联的模板获取内容)。总结一下:

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

所以,在我的筛选编辑视图中,我使用 formRemote 添加模板部分,例如:

<div id="tabs">
<ul>
   <li><a href="#demographics"><span>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 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"><span>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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

万劫不复 2024-11-06 18:54:22

这听起来正在做这些事情:

控制器:

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(模板):

<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>

如果我尝试使用:
update="[success:'reply2', failure:'updateArea']" 在我的 g:formRemote 中,听起来不起作用,我得到 2 个 div(旧的和新的)。我认为这是一个javascript问题。

有人得到更好的东西吗?

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 ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文