实时验证

时间:2011-08-08 23:59:33

标签: scala lift

我正在处理一个注册表单,我希望在twitter上验证用户名。有人可以给我一些我可以开始的提示,有类似已经有效的东西

非常感谢您的关注

1 个答案:

答案 0 :(得分:0)

模板:

 <test:name/><div id="message">

段:

 // helper function, returns function which checks if given string is not-empty
 // and then returns JS with error message
 def notEmpty(anchor: String, message: NodeSeq): String => JsCmd = text =>
     if (text.isEmpty) DisplayMessage(anchor, message, 5 seconds, 1 second) else Noop

 bind("test", template,
     "name" -> SHtml.textAjaxTest(
        "initial value",
        (s:String) => logger.debug("Value changed to: %s".format(s))    
        notEmpty("message", <b>Name must not be empty</b>)
      )
 )

上面的代码应该可行,但我不确定(我复制了更大的应用程序的一部分)。您应该查看Lift API中的SHtml.textAjaxTest方法,并阅读有关Lift中消息的内容。