好的,首先,让我们从我承认绑定 Lift 表单的 bind(...) 方式开始吧!:) 我知道,我只是还没有回去更新这段代码。另外,我现在相信有一些非常巧妙的 Lifty 方法可以做到这一点。这就是我所寻求的。我什至不知道如何一起破解一些东西。那就是说...
我有一个最初显示不可编辑的项目列表,每个项目的标题是一个启用 ajax 的链接,它调用服务器并将该行项目替换为项目的可编辑形式(我使用 SetHtml 交换<li> 中列出该项目的表格)。“父”项目列表视图看起来像这样
<form data-lift="form.ajax">
<div data-lift="creategamewizard?multipart=true" id="wizardform">
<ul>
<li>第1项</li>
<li>第2项</li> li>
</ul>
更多表单元素
<button>提交</button>
< input type="hidden" id='298356928734' />
</div>
<form>
这个 ajax 提交(通过隐藏字段)调用 processSubmit()。
在 editableItem 表单中交换的 SetHtml 看起来像这样。
注意:在以下列表的末尾,“保存”绑定没有与之绑定的服务器端代码,因为“父”提交按钮已经在页面上,并且当我在此绑定中放置另一个隐藏字段或尝试将任何代码直接绑定到“编辑项目保存”按钮,该代码和“父”提交被触发。所以下面的方法是尝试对父提交和编辑项目提交使用“父”提交。
<a href="javascript://" onclick={ajaxOnClickHandler(editItemClickHandler(item.id.get))}>{item.title.get}</a>
def ajaxOnClickHandler(jsHandler: ()=>JsCmd) =
{
SHtml.onEvent( e => jsHandler()).toJsCmd+";return false;"
}
def editItemClickHandler(itemId: String): ()=>JsCmd = ()=>
{
trace.logAjaxComm("ExistingItem.Edit()")
JsCmds.SetHtml("LiId"+itemId, getEditableItem(promo) )
}
def getEditableItem(itemId) =
{
bind( ...
"promotitle" -> SHtml.text(editablePromo.get.promotitle.is,
(s:String) => {
trace.logUIDataManipulation("Saving new promo Title["+s+"]");
editablePromo.get.promotitle(s)
}, "id" -> "promotitle"),
"save" -> SHtml.button("Save", ()=> {})
)
}
然后当用户选择一个项目,并插入可编辑的项目表单时,有一个“另一个”提交按钮,应该 ajax 提交该项目的表单数据,然后换回(现在更新的)不可编辑版本的数据。
我的问题是提交。除了上面的编辑项目表单之外,我在“父”不可编辑列表页面上有一个 ajaxified 提交按钮来处理提交列表下方的一些字段。编辑项“保存”-> 绑定添加了一个按钮,该按钮本身应该(实际上也没有)做任何事情,但它确实触发了“父”提交按钮。我路由该提交以保存编辑项目表单。
不可编辑项目和可编辑项目代码交换正常,但在可编辑项目表单中所做的更改没有保存,我发现这是因为可编辑项目表单中的元素根本没有提交,以下是我根本看不到的日志消息示例...
bind( ... "promotitle" -> SHtml.text(editablePromo.get.promotitle.is,
(s:String) => {
trace.logUIDataManipulation("Saving new promo Title["+s+"]");
editablePromo.get.promotitle(s)
}, "id" -> "promotitle")
)
In a normal ajaxified form, all element handlers are called (if there are changes to the field, I guess...) in order of rendering, with the submit/hidden elements' handlers being called last (if they're last in the bind list.
so finally, let's get around to my question: if you're doing in-place editing like this, how do I manage 2 submit buttons (the one for the non-editable list page plus the additional one that gets added when editing an item)? I'm sure I don't need to refresh the page, but I can't figure out how you'd do this with Ajax. Maybe alternatively, the in-place editable form can be submitted as a non-submit ajax action, ie. somehow that doesn't trigger the parent submit?