Scala lift框架,提交多个值的ajax表单?
我刚刚开始使用 lift,现在尝试将普通形式更改为 ajax 形式,但从未调用方法 processEntryAdd
。
def addUser(xhtml : Group) : NodeSeq = {
var firstName = ""
var lastName = ""
def processEntryAdd() {
Log.info("processEntryAdd: " + firstName + ", " + lastName)
}
SHtml.ajaxForm(
bind("entry", xhtml,
"firstName" -> SHtml.text(firstName,
(x) => {
Log.info("Setting firstName to " + x);
firstName = x
}),
"lastName" -> SHtml.text(lastName,
(x) => {
Log.info("Setting lastName to " + x);
lastName = x
}),
"submit" -> SHtml.submit("Add user", processEntryAdd),
))
}
知道如何实现我想要做的事情,或者为什么上面的代码不起作用。 按下按钮并设置两个局部变量 firstName
和 lastName
时,会提交两个表单字段的值,但不会调用与 SHtml.submit 关联的函数。
谢谢!
I am just getting started with lift and I am now trying to change a normal form to an ajax form but the method processEntryAdd
is never called.
def addUser(xhtml : Group) : NodeSeq = {
var firstName = ""
var lastName = ""
def processEntryAdd() {
Log.info("processEntryAdd: " + firstName + ", " + lastName)
}
SHtml.ajaxForm(
bind("entry", xhtml,
"firstName" -> SHtml.text(firstName,
(x) => {
Log.info("Setting firstName to " + x);
firstName = x
}),
"lastName" -> SHtml.text(lastName,
(x) => {
Log.info("Setting lastName to " + x);
lastName = x
}),
"submit" -> SHtml.submit("Add user", processEntryAdd),
))
}
Any idea how to achieve what I am trying to do, or why the code above doesn't work.
The values of the two form fields are submitted when the button is pressed and the two local variables firstName
and lastName
are set but the function associated with SHtml.submit isn't called.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这个问题有点老了,但我最近需要自己知道这一点,这是迄今为止我见过的最好的解决方案:
通过将处理添加到隐藏的表单元素,您可以保留提交按钮,而不需要更改任何内容查看代码。
您可以通过让 processEntryAdd() 返回 JsCmd 来添加客户端行为:
This question is kind of old, but I recently needed to know this myself, and this is the best solution I've seen so far:
By adding the processing to a hidden form element you get to keep the the submit button, without changing any view code.
You can add client side behaviour by having processEntryAdd() return a JsCmd:
在回答这个问题时,David Pollak 建议使用
“提交”-> SHtml.hidden("添加用户", processEntryAdd) ++
在电梯邮件列表上。
In response to this question David Pollak suggested using
"submit" -> SHtml.hidden("Add user", processEntryAdd) ++
on the lift mailing list.
这就是答案,滚动到底部,(忽略<之后的第一个空格)
http:// /www.assembla.com/wiki/show/liftweb/ajaxForm
“提交”-> (SHtml.hidden(auth) ++ <输入类型=“提交”值=“登录”/>)
Here's the answer, scroll to the bottom, (ignore the first space after <)
http://www.assembla.com/wiki/show/liftweb/ajaxForm
"submit" -> (SHtml.hidden(auth) ++ < input type="submit" value="Login"/>)