开发者

live validation

开发者 https://www.devze.com 2023-03-27 03:14 出处:网络
I\'m working on a signup form, and I want to live a validation of the user name as on twitter. Someone can give me some tips where I can start, there is s开发者_Go百科omething similar already worked

I'm working on a signup form, and I want to live a validation of the user name as on twitter. Someone can give me some tips where I can start, there is s开发者_Go百科omething similar already worked

Thank you very much for your attention


Template:

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

Snippet:

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

Above code should work, but I'm not sure (I copied part of bigger application). You should look at SHtml.textAjaxTest method in Lift API and read something about messages in Lift.

0

精彩评论

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