exploring lift javascript example

105 views
Skip to first unread message

I D

unread,
Jul 17, 2011, 11:01:41 PM7/17/11
to Lift
I was attempting to implement the simple form validation javascript
example from Exploring Lift and ran into an error.

I have posted below the working bind that I commented out and the
error causing bind that was my failed attempt at implementing the
validation javascript.

bind("test", xhtml,
"blog_title" -> SHtml.text(blog_title, blog_title = _, "id" -
> "blogtitle"),
"submit" -> SHtml.submit("Post", newBlog, "onclick" ->
JsIf(JsEq(ValById("blogtitle"), ""),
Alert("You must provide a value") & JsReturn(false))))

/*
bind("test", xhtml,
"blog_title" -> SHtml.text(blog_title, blog_title = _),
"submit" -> SHtml.submit("Post", newBlog))
*/

I received a "type mismatch" error that stated
[INFO] found : (String, net.liftweb.http.js.JsCmd)
[INFO] required: net.liftweb.http.SHtml.ElemAttr
[INFO] "submit" -> SHtml.submit("Post", newBlog, "onclick" ->
JsIf(JsEq(ValById("blogtitle"), ""),

I understand that the third parameter is suppose to be an ElemAttr but
I was just following the example and don;t really know where to go
next since I am just starting..

http://exploring.liftweb.net/master/index-10.html#toc-Section-10.1







I have been playing around with Scala/Lift for around a month and have
made some assumptions that I would like to confirm.

Derek Chen-Becker

unread,
Jul 18, 2011, 12:24:12 PM7/18/11
to lif...@googlegroups.com
I don't have time to dig through the docs/code, but what I think you might be getting an implicit conversion here that's making the "onclick" into something that has a "->" method. Maybe. Could you try changing it to

SHtml.submit("Post", newBlog, ("onclick", ...your JS here...))

Using (A,B) for Pair instead of A -> B might avoid it. Please let me know if this works.

Derek


--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.


I D

unread,
Jul 19, 2011, 12:18:52 AM7/19/11
to Lift
Thanks. I received the same error. I should have also stated that I am
using scala 2.8.1 and lift 2.3.

On Jul 18, 12:24 pm, Derek Chen-Becker <dchenbec...@gmail.com> wrote:
> I don't have time to dig through the docs/code, but what I think you might
> be getting an implicit conversion here that's making the "onclick" into
> something that has a "->" method. Maybe. Could you try changing it to
>
> SHtml.submit("Post", newBlog, ("onclick", ...your JS here...))
>
> Using (A,B) for Pair instead of A -> B might avoid it. Please let me know if
> this works.
>
> Derek
>

Antonio Salazar Cardozo

unread,
Jul 19, 2011, 8:55:59 AM7/19/11
to lif...@googlegroups.com
I think it's the opposite; you're missing an implicit conversion.

Try importing SHtml._. If that doesn't work, try doing:

"onclick" -> 
  (JsIf(JsEq(ValById("blogtitle"), ""), 
      Alert("You must provide a value") & JsReturn(false))).toJsCmd


And see if that makes things work.
Thanks,
Antonio

I D

unread,
Jul 19, 2011, 6:00:25 PM7/19/11
to Lift
your second suggestion worked. thanks!

On Jul 19, 8:55 am, Antonio Salazar Cardozo <savedfastc...@gmail.com>
wrote:

Antonio Salazar Cardozo

unread,
Jul 19, 2011, 6:55:27 PM7/19/11
to lif...@googlegroups.com
Awesome. Yeah, you needed to trigger the implicit (String, String) to ElemAttr conversion, but I guess it wasn't catching a JsCmd->String implicit or perhaps there simply isn't one. toJsCmd will convert the JsCmd to a String, thus making the overall expression a (String, String), which then gets converted to an ElemAttr for you :)
Thanks,
Antonio
Reply all
Reply to author
Forward
0 new messages