[Lift] Re: Problem with FocusOnLoad and passing attributes through bind
Thanks for responding Marius. You're right, my doSearch method doesn't need the msg parameter -- that was just an artifact of transforming an example (removed now). As far as my specific issue, I guess you're saying the best solution is for the framework to add overload def -%(in: NodeSeq = NodeSeq) congruent with - -- should I file a feature request? As you said, Group(FocusOnLoad...) doesn't compile either because it returns a Node, not the currently required Element. Did I misunderstand? In the short term how would you solve this ? Thanks, - Luke On Mar 6, 1:39 am, Marius marius.dan...@gmail.com wrote: On 22 feb., 04:12, Luke Nezda lne...@gmail.com wrote: Hello, I am new to Scala and Lift. I am having a problem using 2 features together which seem to work fine individually. Here's a simplified piece of the code: class Ajax { def someResult(q:String) = spansome results for query {q}.../ span // searchField closure def searchField(xhtml: NodeSeq): NodeSeq = { // build up an ajax text box def doSearch(msg: NodeSeq) = { // doesn't compile with bind: searchBox -% doSearch _ FocusOnLoad(SHtml.ajaxText(, q = SetHtml(resultz, someResult(q // compiles with bind: searchBox -% doSearch _ // SHtml.ajaxText(, q = SetHtml(resultz, someResult(q))) } // bind the view to the functionality bind(ajax, xhtml, searchBox - doSearch _ // doesn't compile if doSearch returns result of FocusOnLoad //searchBox -% doSearch _ ) } } and the template invocation: lift:surround with=default at=content lift:Ajax.searchField id_msgs=messages ajax:searchBox class=text type=search tabindex=1 / hr class=space/ div id=resultz/div div id=messages/div /lift:Ajax.searchField /lift:surround My goal is an Ajax-enabled text input that gets focus when the page loads and has various attributes of the input element set. I realize I can use the SHtml.ajaxText variant that takes attribute-value pairs, as in: FocusOnLoad(SHtml.ajaxText(, q = SetHtml(resultz, Yawni.query(q)), (class, text), (type, search), (tabindex, 1))) but I'm trying to keep the various element attributes in the template. When I try to bind with: searchBox -% doSearch _ instead of: searchBox - doSearch _ I get the following compile error: snippet/Ajax.scala:109: error: overloaded method value -% with alternatives ((scala.xml.NodeSeq) = scala.xml.Elem)net.liftweb.util.Helpers.FuncBindParam and (Option[scala.xml.Elem])net.liftweb.util.Helpers.FuncBindParam and (net.liftweb.common.Box[scala.xml.Elem])net.liftweb.util.Helpers.FuncBindPa ram and (scala.xml.Elem)net.liftweb.util.Helpers.FuncBindParam cannot be applied to ((scala.xml.NodeSeq) = scala.xml.NodeSeq) searchBox -% doSearch _ ^ one error found Why your doSearch function takes a msg parameter? ... it doesn't seam to use it. doSearch _ is a partially applied function and acts as a (NodeSeq) = NodeSeq however -% has only a definition like: def -%(in: NodeSeq = Elem) while - also has def -(in: NodeSeq = NodeSeq) which is why you get the compile error. We should add the same definition for NodeSeq = NodeSeq You can simply say: searchBox -% doSearch and have def doSearch: NodeSeq = ... FocusOnLoad returns a NodeSeq because it returns a sequence of nodes which conceptually cannot be converted to an elem. You could try to have a Group(FocusOnLoad ...) ... but Group is a Node not an Elem. Between all the bind() and -()/-%() overloads and my general Scala / Lift ignorance, I can't understand what the right way to resolve this is. I think it has something to do with FocusOnLoad returning a NodeSeq (input/script/) vs. an Element, but I don't know where to go from here... Thanks in advance, - Luke -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.
[Lift] Re: Problem with FocusOnLoad and passing attributes through bind
Thanks for responding Marius. You're right, my doSearch method doesn't need the msg parameter -- that was just an artifact of transforming an example (removed now). As far as my specific issue, I guess you're saying the best solution is for the framework to add overload def -%(in: NodeSeq = NodeSeq) congruent with - -- should I file a feature request? As you said, Group(FocusOnLoad...) doesn't compile either because it returns a Node, not the currently required Element. Did I misunderstand? In the short term how would you solve this ? Thanks, - Luke On Mar 6, 1:39 am, Marius marius.dan...@gmail.com wrote: On 22 feb., 04:12, Luke Nezda lne...@gmail.com wrote: Hello, I am new to Scala and Lift. I am having a problem using 2 features together which seem to work fine individually. Here's a simplified piece of the code: class Ajax { def someResult(q:String) = spansome results for query {q}.../ span // searchField closure def searchField(xhtml: NodeSeq): NodeSeq = { // build up an ajax text box def doSearch(msg: NodeSeq) = { // doesn't compile with bind: searchBox -% doSearch _ FocusOnLoad(SHtml.ajaxText(, q = SetHtml(resultz, someResult(q // compiles with bind: searchBox -% doSearch _ // SHtml.ajaxText(, q = SetHtml(resultz, someResult(q))) } // bind the view to the functionality bind(ajax, xhtml, searchBox - doSearch _ // doesn't compile if doSearch returns result of FocusOnLoad //searchBox -% doSearch _ ) } } and the template invocation: lift:surround with=default at=content lift:Ajax.searchField id_msgs=messages ajax:searchBox class=text type=search tabindex=1 / hr class=space/ div id=resultz/div div id=messages/div /lift:Ajax.searchField /lift:surround My goal is an Ajax-enabled text input that gets focus when the page loads and has various attributes of the input element set. I realize I can use the SHtml.ajaxText variant that takes attribute-value pairs, as in: FocusOnLoad(SHtml.ajaxText(, q = SetHtml(resultz, Yawni.query(q)), (class, text), (type, search), (tabindex, 1))) but I'm trying to keep the various element attributes in the template. When I try to bind with: searchBox -% doSearch _ instead of: searchBox - doSearch _ I get the following compile error: snippet/Ajax.scala:109: error: overloaded method value -% with alternatives ((scala.xml.NodeSeq) = scala.xml.Elem)net.liftweb.util.Helpers.FuncBindParam and (Option[scala.xml.Elem])net.liftweb.util.Helpers.FuncBindParam and (net.liftweb.common.Box[scala.xml.Elem])net.liftweb.util.Helpers.FuncBindPa ram and (scala.xml.Elem)net.liftweb.util.Helpers.FuncBindParam cannot be applied to ((scala.xml.NodeSeq) = scala.xml.NodeSeq) searchBox -% doSearch _ ^ one error found Why your doSearch function takes a msg parameter? ... it doesn't seam to use it. doSearch _ is a partially applied function and acts as a (NodeSeq) = NodeSeq however -% has only a definition like: def -%(in: NodeSeq = Elem) while - also has def -(in: NodeSeq = NodeSeq) which is why you get the compile error. We should add the same definition for NodeSeq = NodeSeq You can simply say: searchBox -% doSearch and have def doSearch: NodeSeq = ... FocusOnLoad returns a NodeSeq because it returns a sequence of nodes which conceptually cannot be converted to an elem. You could try to have a Group(FocusOnLoad ...) ... but Group is a Node not an Elem. Between all the bind() and -()/-%() overloads and my general Scala / Lift ignorance, I can't understand what the right way to resolve this is. I think it has something to do with FocusOnLoad returning a NodeSeq (input/script/) vs. an Element, but I don't know where to go from here... Thanks in advance, - Luke -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.
[Lift] Re: Problem with FocusOnLoad and passing attributes through bind
In the short term you would solve it as I suggested: Use in your bind searchBox -% doSearch and define your doSearch as: def doSearch: NodeSeq = { ... do your stuff here } Actually thinking more into it there is a good reason for -% to not have a (NodeSeq) = NodeSeq support. -% means that it preserves the attributes specified in the template to the resulting node.But having a bunch of attributes we can't apply them to a NodeSeq because aa NodeSeq means a sequence of Nodes with no commn parent so we can;t determine to which node we'd apply those attributes. AFAIK only an Elem can have attributes. On Mar 6, 6:45 pm, Luke Nezda lne...@gmail.com wrote: Thanks for responding Marius. You're right, my doSearch method doesn't need the msg parameter -- that was just an artifact of transforming an example (removed now). As far as my specific issue, I guess you're saying the best solution is for the framework to add overload def -%(in: NodeSeq = NodeSeq) congruent with - -- should I file a feature request? As you said, Group(FocusOnLoad...) doesn't compile either because it returns a Node, not the currently required Element. Did I misunderstand? You are correct. I mainly pointed to Group just as a reminder as it can be useful to aggregate nodes. It wont work in your case. In the short term how would you solve this ? Thanks, - Luke On Mar 6, 1:39 am, Marius marius.dan...@gmail.com wrote: On 22 feb., 04:12, Luke Nezda lne...@gmail.com wrote: Hello, I am new to Scala and Lift. I am having a problem using 2 features together which seem to work fine individually. Here's a simplified piece of the code: class Ajax { def someResult(q:String) = spansome results for query {q}.../ span // searchField closure def searchField(xhtml: NodeSeq): NodeSeq = { // build up an ajax text box def doSearch(msg: NodeSeq) = { // doesn't compile with bind: searchBox -% doSearch _ FocusOnLoad(SHtml.ajaxText(, q = SetHtml(resultz, someResult(q // compiles with bind: searchBox -% doSearch _ // SHtml.ajaxText(, q = SetHtml(resultz, someResult(q))) } // bind the view to the functionality bind(ajax, xhtml, searchBox - doSearch _ // doesn't compile if doSearch returns result of FocusOnLoad //searchBox -% doSearch _ ) } } and the template invocation: lift:surround with=default at=content lift:Ajax.searchField id_msgs=messages ajax:searchBox class=text type=search tabindex=1 / hr class=space/ div id=resultz/div div id=messages/div /lift:Ajax.searchField /lift:surround My goal is an Ajax-enabled text input that gets focus when the page loads and has various attributes of the input element set. I realize I can use the SHtml.ajaxText variant that takes attribute-value pairs, as in: FocusOnLoad(SHtml.ajaxText(, q = SetHtml(resultz, Yawni.query(q)), (class, text), (type, search), (tabindex, 1))) but I'm trying to keep the various element attributes in the template. When I try to bind with: searchBox -% doSearch _ instead of: searchBox - doSearch _ I get the following compile error: snippet/Ajax.scala:109: error: overloaded method value -% with alternatives ((scala.xml.NodeSeq) = scala.xml.Elem)net.liftweb.util.Helpers.FuncBindParam and (Option[scala.xml.Elem])net.liftweb.util.Helpers.FuncBindParam and (net.liftweb.common.Box[scala.xml.Elem])net.liftweb.util.Helpers.FuncBindPa ram and (scala.xml.Elem)net.liftweb.util.Helpers.FuncBindParam cannot be applied to ((scala.xml.NodeSeq) = scala.xml.NodeSeq) searchBox -% doSearch _ ^ one error found Why your doSearch function takes a msg parameter? ... it doesn't seam to use it. doSearch _ is a partially applied function and acts as a (NodeSeq) = NodeSeq however -% has only a definition like: def -%(in: NodeSeq = Elem) while - also has def -(in: NodeSeq = NodeSeq) which is why you get the compile error. We should add the same definition for NodeSeq = NodeSeq You can simply say: searchBox -% doSearch and have def doSearch: NodeSeq = ... FocusOnLoad returns a NodeSeq because it returns a sequence of nodes which conceptually cannot be converted to an elem. You could try to have a Group(FocusOnLoad ...) ... but Group is a Node not an Elem. Between all the bind() and -()/-%() overloads and my general Scala / Lift ignorance, I can't understand what the right way to resolve this is. I think it has something to do with FocusOnLoad returning a NodeSeq (input/script/) vs. an Element, but I don't know where to go from here... Thanks in advance, - Luke -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to
[Lift] Re: Problem with FocusOnLoad and passing attributes through bind
You could also do it like this: bind(ajax, xhtml, searchBox -% SHtml.ajaxText(, q = SetHtml(resultz, Yawni.query(q)) ) ++ Script(JqOnLoad(SetValueAndFocus(myfield, ))) SetValueAndFocus is already in JqJsCmds but it really should in in JsCmds as it does not depend on JQuery. On Mar 6, 10:10 pm, Marius marius.dan...@gmail.com wrote: Ahh sorry for not posting this earlier. Assume you know the id of your text box (say myfield) and you're using JQuery. import net.liftweb.http.js.jquery._ bind(ajax, xhtml, searchBox -% SHtml.ajaxText(, q = SetHtml(resultz, Yawni.query(q)) ) ++ Script(JqOnLoad(JqFocus(myfield))) where: object JqFocus { def apply(id : String) = JqId(id) new JsExp with JQueryRight { def toJsCmd = focus() } } I can add JqFocus to Lift tomorrow (by opening a ticket) but could you please try it first? Br's, Marius On Mar 6, 9:00 pm, Luke Nezda lne...@gmail.com wrote: Marius - First, thank you for your time! (sorry for the accidental double response post - browser fail :)) Ok, so below is my current solution. What I don't understand is how to avoid hard coding the attributes when constructing the SHtml.ajaxText AND getting that ajaxText's input to FocusOnLoad. I understand how to leave off the parameter for doSearch (fixed below -- you're totally right, that was spurious) and I understand that passing through attributes to a whole NodeSeq doesn't make much sense. What I'm wondering is if there's some way of achieving both: FocusOnLoad attribute pass through -- maybe a nested bind or something? Thanks again, - Luke // get FocusOnLoad, hard code attributes object AjaxWithFocusOnLoad extends DispatchSnippet { override def dispatch = { case searchField = searchField } // searchField closure def searchField(xhtml: NodeSeq): NodeSeq = { // build up an ajax text box def doSearch:NodeSeq = { FocusOnLoad(SHtml.ajaxText(, q = SetHtml(resultz, Yawni.query(q)), (size,30), (tabindex, 1), (type, search))) } // bind the view to the functionality bind(ajax, xhtml, searchBox - doSearch ) } } // ditch FocusOnLoad functionality, take advantage of attribute pass through object AjaxWithAttributePassThrough extends DispatchSnippet { override def dispatch = { case searchField = searchField } // searchField closure def searchField(xhtml: NodeSeq): NodeSeq = { // build up an ajax text box def doSearch:Elem = { //FocusOnLoad(SHtml.ajaxText(, q = SetHtml(resultz, Yawni.query(q)), (size,30), (tabindex, 1), (type, search))) // kill FocusOnLoad functionality, take advantage of attribute pass through in bind below SHtml.ajaxText(, q = SetHtml(resultz, Yawni.query(q))) } // bind the view to the functionality bind(ajax, xhtml, //searchBox - doSearch // use attribute pass through variant searchBox -% doSearch ) } } On Mar 6, 10:57 am, Marius marius.dan...@gmail.com wrote: In the short term you would solve it as I suggested: Use in your bind searchBox -% doSearch and define your doSearch as: def doSearch: NodeSeq = { ... do your stuff here } Actually thinking more into it there is a good reason for -% to not have a (NodeSeq) = NodeSeq support. -% means that it preserves the attributes specified in the template to the resulting node.But having a bunch of attributes we can't apply them to a NodeSeq because aa NodeSeq means a sequence of Nodes with no commn parent so we can;t determine to which node we'd apply those attributes. AFAIK only an Elem can have attributes. On Mar 6, 6:45 pm, Luke Nezda lne...@gmail.com wrote: Thanks for responding Marius. You're right, my doSearch method doesn't need the msg parameter -- that was just an artifact of transforming an example (removed now). As far as my specific issue, I guess you're saying the best solution is for the framework to add overload def -%(in: NodeSeq = NodeSeq) congruent with - -- should I file a feature request? As you said, Group(FocusOnLoad...) doesn't compile either because it returns a Node, not the currently required Element. Did I misunderstand? You are correct. I mainly pointed to Group just as a reminder as it can be useful to aggregate nodes. It wont work in your case. In the short term how would you solve this ? Thanks, - Luke On Mar 6, 1:39 am, Marius marius.dan...@gmail.com wrote: On 22 feb., 04:12, Luke Nezda lne...@gmail.com wrote: Hello, I am new to Scala and Lift. I am having a problem using 2 features together which seem to work fine individually. Here's a simplified piece of the code: class Ajax { def someResult(q:String) = spansome
[Lift] Re: Problem with FocusOnLoad and passing attributes through bind
Hi, Marius - Ok, I think I catch the drift of your solution. You said: bind(ajax, xhtml, searchBox -% SHtml.ajaxText(, q = SetHtml(resultz, Yawni.query(q)) ) ++ Script(JqOnLoad(SetValueAndFocus(myfield, ))) which is missing a paren -- I think you meant: bind(ajax, xhtml, searchBox -% SHtml.ajaxText(, q = SetHtml(resultz, Yawni.query(q))) ) ++ Script(JqOnLoad(SetValueAndFocus(myfield, ))) The gist of your solution is to append a Script (which references the ajaxText input element by a manually introduced id) onto the NodeSeq returned by bind() right ? It works, and I appreciate your assistance, though it seems a shame to have to give up the slick, functional FocusOnLoad wrapper, add an id, and bolt this onto the end. Thanks, - Luke On Mar 6, 2:39 pm, Marius marius.dan...@gmail.com wrote: You could also do it like this: bind(ajax, xhtml, searchBox -% SHtml.ajaxText(, q = SetHtml(resultz, Yawni.query(q)) ) ++ Script(JqOnLoad(SetValueAndFocus(myfield, ))) SetValueAndFocus is already in JqJsCmds but it really should in in JsCmds as it does not depend on JQuery. On Mar 6, 10:10 pm, Marius marius.dan...@gmail.com wrote: Ahh sorry for not posting this earlier. Assume you know the id of your text box (say myfield) and you're using JQuery. import net.liftweb.http.js.jquery._ bind(ajax, xhtml, searchBox -% SHtml.ajaxText(, q = SetHtml(resultz, Yawni.query(q)) ) ++ Script(JqOnLoad(JqFocus(myfield))) where: object JqFocus { def apply(id : String) = JqId(id) new JsExp with JQueryRight { def toJsCmd = focus() } } I can add JqFocus to Lift tomorrow (by opening a ticket) but could you please try it first? Br's, Marius On Mar 6, 9:00 pm, Luke Nezda lne...@gmail.com wrote: Marius - First, thank you for your time! (sorry for the accidental double response post - browser fail :)) Ok, so below is my current solution. What I don't understand is how to avoid hard coding the attributes when constructing the SHtml.ajaxText AND getting that ajaxText's input to FocusOnLoad. I understand how to leave off the parameter for doSearch (fixed below -- you're totally right, that was spurious) and I understand that passing through attributes to a whole NodeSeq doesn't make much sense. What I'm wondering is if there's some way of achieving both: FocusOnLoad attribute pass through -- maybe a nested bind or something? Thanks again, - Luke // get FocusOnLoad, hard code attributes object AjaxWithFocusOnLoad extends DispatchSnippet { override def dispatch = { case searchField = searchField } // searchField closure def searchField(xhtml: NodeSeq): NodeSeq = { // build up an ajax text box def doSearch:NodeSeq = { FocusOnLoad(SHtml.ajaxText(, q = SetHtml(resultz, Yawni.query(q)), (size,30), (tabindex, 1), (type, search))) } // bind the view to the functionality bind(ajax, xhtml, searchBox - doSearch ) } } // ditch FocusOnLoad functionality, take advantage of attribute pass through object AjaxWithAttributePassThrough extends DispatchSnippet { override def dispatch = { case searchField = searchField } // searchField closure def searchField(xhtml: NodeSeq): NodeSeq = { // build up an ajax text box def doSearch:Elem = { //FocusOnLoad(SHtml.ajaxText(, q = SetHtml(resultz, Yawni.query(q)), (size,30), (tabindex, 1), (type, search))) // kill FocusOnLoad functionality, take advantage of attribute pass through in bind below SHtml.ajaxText(, q = SetHtml(resultz, Yawni.query(q))) } // bind the view to the functionality bind(ajax, xhtml, //searchBox - doSearch // use attribute pass through variant searchBox -% doSearch ) } } On Mar 6, 10:57 am, Marius marius.dan...@gmail.com wrote: In the short term you would solve it as I suggested: Use in your bind searchBox -% doSearch and define your doSearch as: def doSearch: NodeSeq = { ... do your stuff here } Actually thinking more into it there is a good reason for -% to not have a (NodeSeq) = NodeSeq support. -% means that it preserves the attributes specified in the template to the resulting node.But having a bunch of attributes we can't apply them to a NodeSeq because aa NodeSeq means a sequence of Nodes with no commn parent so we can;t determine to which node we'd apply those attributes. AFAIK only an Elem can have attributes. On Mar 6, 6:45 pm, Luke Nezda lne...@gmail.com wrote: Thanks for responding Marius. You're right, my doSearch method doesn't need the msg parameter -- that was just an artifact of transforming an example
[Lift] Re: Problem with FocusOnLoad and passing attributes through bind
Yes you understanding is correct. FocusOnLoad is not an appropriate solution for your particular problem as -% and FocusOnLoad operate on two different types which are not interchangeable due to attributes preservation as you well noticed. Besides the solution I posted above is similar with what FocusOnLoad does except that it does the Script append a bit later on. FocusOnLoad is not really functional well not in the sense of functional programming :) There are other approaches of course but would require more coding as form the NodeSeq produced by FocusOnLoad(Shtml.ajaxText()) pattern match for the Elem you want that add the attributes. You could of course put the js code that puts the focus on your field right in your template in the script tag and this would require no Scala code for it. you code would simply be bind(ajax, xhtml, searchBox -% SHtml.ajaxText(, q = SetHtml(resultz, Yawni.query(q))) ) and in your template script type=text/javascript $(document).ready(function() { $(#myfield).focus(); }); /script On 6 mar., 23:56, Luke Nezda lne...@gmail.com wrote: Hi, Marius - Ok, I think I catch the drift of your solution. You said: bind(ajax, xhtml, searchBox -% SHtml.ajaxText(, q = SetHtml(resultz, Yawni.query(q)) ) ++ Script(JqOnLoad(SetValueAndFocus(myfield, ))) which is missing a paren -- I think you meant: bind(ajax, xhtml, searchBox -% SHtml.ajaxText(, q = SetHtml(resultz, Yawni.query(q))) ) ++ Script(JqOnLoad(SetValueAndFocus(myfield, ))) The gist of your solution is to append a Script (which references the ajaxText input element by a manually introduced id) onto the NodeSeq returned by bind() right ? It works, and I appreciate your assistance, though it seems a shame to have to give up the slick, functional FocusOnLoad wrapper, add an id, and bolt this onto the end. Thanks, - Luke On Mar 6, 2:39 pm, Marius marius.dan...@gmail.com wrote: You could also do it like this: bind(ajax, xhtml, searchBox -% SHtml.ajaxText(, q = SetHtml(resultz, Yawni.query(q)) ) ++ Script(JqOnLoad(SetValueAndFocus(myfield, ))) SetValueAndFocus is already in JqJsCmds but it really should in in JsCmds as it does not depend on JQuery. On Mar 6, 10:10 pm, Marius marius.dan...@gmail.com wrote: Ahh sorry for not posting this earlier. Assume you know the id of your text box (say myfield) and you're using JQuery. import net.liftweb.http.js.jquery._ bind(ajax, xhtml, searchBox -% SHtml.ajaxText(, q = SetHtml(resultz, Yawni.query(q)) ) ++ Script(JqOnLoad(JqFocus(myfield))) where: object JqFocus { def apply(id : String) = JqId(id) new JsExp with JQueryRight { def toJsCmd = focus() } } I can add JqFocus to Lift tomorrow (by opening a ticket) but could you please try it first? Br's, Marius On Mar 6, 9:00 pm, Luke Nezda lne...@gmail.com wrote: Marius - First, thank you for your time! (sorry for the accidental double response post - browser fail :)) Ok, so below is my current solution. What I don't understand is how to avoid hard coding the attributes when constructing the SHtml.ajaxText AND getting that ajaxText's input to FocusOnLoad. I understand how to leave off the parameter for doSearch (fixed below -- you're totally right, that was spurious) and I understand that passing through attributes to a whole NodeSeq doesn't make much sense. What I'm wondering is if there's some way of achieving both: FocusOnLoad attribute pass through -- maybe a nested bind or something? Thanks again, - Luke // get FocusOnLoad, hard code attributes object AjaxWithFocusOnLoad extends DispatchSnippet { override def dispatch = { case searchField = searchField } // searchField closure def searchField(xhtml: NodeSeq): NodeSeq = { // build up an ajax text box def doSearch:NodeSeq = { FocusOnLoad(SHtml.ajaxText(, q = SetHtml(resultz, Yawni.query(q)), (size,30), (tabindex, 1), (type, search))) } // bind the view to the functionality bind(ajax, xhtml, searchBox - doSearch ) } } // ditch FocusOnLoad functionality, take advantage of attribute pass through object AjaxWithAttributePassThrough extends DispatchSnippet { override def dispatch = { case searchField = searchField } // searchField closure def searchField(xhtml: NodeSeq): NodeSeq = { // build up an ajax text box def doSearch:Elem = { //FocusOnLoad(SHtml.ajaxText(, q = SetHtml(resultz, Yawni.query(q)), (size,30), (tabindex, 1), (type, search))) // kill FocusOnLoad functionality, take advantage of attribute pass through in bind below SHtml.ajaxText(, q =
[Lift] Re: Problem with FocusOnLoad and passing attributes through bind
On Mar 6, 10:57 am, Marius marius.dan...@gmail.com wrote: Actually thinking more into it there is a good reason for -% to not have a (NodeSeq) = NodeSeq support. -% means that it preserves the attributes specified in the template to the resulting node.But having a bunch of attributes we can't apply them to a NodeSeq because aa NodeSeq means a sequence of Nodes with no commn parent so we can;t determine to which node we'd apply those attributes. AFAIK only an Elem can have attributes. Why not just map the attributes over all of the top level elements in the nodeseq? scala val a = p class=blahtemplate/p.attributes a: scala.xml.MetaData = class=blah scala val s:NodeSeq = pfirst para/ppsecond para bwith nested stuff/b/p s: scala.xml.NodeSeq = pfirst para/ppsecond para bwith nested stuff/b/p scala val result: NodeSeq = s.map( { case e: Elem = e % a; case n = n } ) result: scala.xml.NodeSeq = p class=blahfirst para/pp class=blahsecond para bwith nested stuff/b/p This is semantically just fine with regard to, say, an attribute of class. Its the designer's own fault if they put in an attribute of id into a tag that may get repeated. As I recall, the current behavior of -% leads to some annoying inconsistencies compared to -, eg not being able to just return NodeSeq.Empty if you want to get rid of a bound tag. -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.
Re: [Lift] Re: Problem with FocusOnLoad and passing attributes through bind
The fundamental problem is that at the top bind level you want to use FocusOnLoad which returns a NodeSeq, but you also want bind to pass along the attributes, which has to operate at a lower level. So you can use bind twice, nested. Try this pattern: bind(pre, xhtml, label - {ns: NodeSeq = FocusOnLoad( bind(pre, ns, label -% elem ) ) } ) - Luke Nezdalne...@gmail.com wrote: Marius - First, thank you for your time! (sorry for the accidental double response post - browser fail :)) Ok, so below is my current solution. What I don't understand is how to avoid hard coding the attributes when constructing the SHtml.ajaxText AND getting that ajaxText's input to FocusOnLoad. I understand how to leave off the parameter for doSearch (fixed below -- you're totally right, that was spurious) and I understand that passing through attributes to a whole NodeSeq doesn't make much sense. What I'm wondering is if there's some way of achieving both: FocusOnLoad attribute pass through -- maybe a nested bind or something? Thanks again, - Luke // get FocusOnLoad, hard code attributes object AjaxWithFocusOnLoad extends DispatchSnippet { override def dispatch = { case searchField = searchField } // searchField closure def searchField(xhtml: NodeSeq): NodeSeq = { // build up an ajax text box def doSearch:NodeSeq = { FocusOnLoad(SHtml.ajaxText(, q = SetHtml(resultz, Yawni.query(q)), (size,30), (tabindex, 1), (type, search))) } // bind the view to the functionality bind(ajax, xhtml, searchBox - doSearch ) } } // ditch FocusOnLoad functionality, take advantage of attribute pass through object AjaxWithAttributePassThrough extends DispatchSnippet { override def dispatch = { case searchField = searchField } // searchField closure def searchField(xhtml: NodeSeq): NodeSeq = { // build up an ajax text box def doSearch:Elem = { //FocusOnLoad(SHtml.ajaxText(, q = SetHtml(resultz, Yawni.query(q)), (size,30), (tabindex, 1), (type, search))) // kill FocusOnLoad functionality, take advantage of attribute pass through in bind below SHtml.ajaxText(, q = SetHtml(resultz, Yawni.query(q))) } // bind the view to the functionality bind(ajax, xhtml, //searchBox - doSearch // use attribute pass through variant searchBox -% doSearch ) } } On Mar 6, 10:57 am, Marius marius.dan...@gmail.com wrote: In the short term you would solve it as I suggested: Use in your bind searchBox -% doSearch and define your doSearch as: def doSearch: NodeSeq = { ... do your stuff here } Actually thinking more into it there is a good reason for -% to not have a (NodeSeq) = NodeSeq support. -% means that it preserves the attributes specified in the template to the resulting node.But having a bunch of attributes we can't apply them to a NodeSeq because aa NodeSeq means a sequence of Nodes with no commn parent so we can;t determine to which node we'd apply those attributes. AFAIK only an Elem can have attributes. On Mar 6, 6:45 pm, Luke Nezda lne...@gmail.com wrote: Thanks for responding Marius. You're right, my doSearch method doesn't need the msg parameter -- that was just an artifact of transforming an example (removed now). As far as my specific issue, I guess you're saying the best solution is for the framework to add overload def -%(in: NodeSeq = NodeSeq) congruent with - -- should I file a feature request? As you said, Group(FocusOnLoad...) doesn't compile either because it returns a Node, not the currently required Element. Did I misunderstand? You are correct. I mainly pointed to Group just as a reminder as it can be useful to aggregate nodes. It wont work in your case. In the short term how would you solve this ? Thanks, - Luke On Mar 6, 1:39 am, Marius marius.dan...@gmail.com wrote: On 22 feb., 04:12, Luke Nezda lne...@gmail.com wrote: Hello, I am new to Scala and Lift. I am having a problem using 2 features together which seem to work fine individually. Here's a simplified piece of the code: class Ajax { def someResult(q:String) = spansome results for query {q}.../ span // searchField closure def searchField(xhtml: NodeSeq): NodeSeq = { // build up an ajax text box def doSearch(msg: NodeSeq) = { // doesn't compile with bind: searchBox -% doSearch _ FocusOnLoad(SHtml.ajaxText(, q = SetHtml(resultz, someResult(q // compiles with bind: searchBox -% doSearch _ // SHtml.ajaxText(, q = SetHtml(resultz, someResult(q))) } // bind the view to the functionality bind(ajax, xhtml, searchBox - doSearch _ // doesn't compile if doSearch returns result of FocusOnLoad //searchBox -% doSearch _ ) } }
[Lift] Re: Problem with FocusOnLoad and passing attributes through bind
Hello, Bumping my own post since I hadn't received any feedback on this in a few weeks. Maybe I didn't describe my issue well ? Thanks in advance, - Luke On Feb 21, 8:12 pm, Luke Nezda lne...@gmail.com wrote: Hello, I am new to Scala and Lift. I am having a problem using 2 features together which seem to work fine individually. Here's a simplified piece of the code: class Ajax { def someResult(q:String) = spansome results for query {q}.../ span // searchField closure def searchField(xhtml: NodeSeq): NodeSeq = { // build up an ajax text box def doSearch(msg: NodeSeq) = { // doesn't compile with bind: searchBox -% doSearch _ FocusOnLoad(SHtml.ajaxText(, q = SetHtml(resultz, someResult(q // compiles with bind: searchBox -% doSearch _ // SHtml.ajaxText(, q = SetHtml(resultz, someResult(q))) } // bind the view to the functionality bind(ajax, xhtml, searchBox - doSearch _ // doesn't compile if doSearch returns result of FocusOnLoad //searchBox -% doSearch _ ) } } and the template invocation: lift:surround with=default at=content lift:Ajax.searchField id_msgs=messages ajax:searchBox class=text type=search tabindex=1 / hr class=space/ div id=resultz/div div id=messages/div /lift:Ajax.searchField /lift:surround My goal is an Ajax-enabled text input that gets focus when the page loads and has various attributes of the input element set. I realize I can use the SHtml.ajaxText variant that takes attribute-value pairs, as in: FocusOnLoad(SHtml.ajaxText(, q = SetHtml(resultz, Yawni.query(q)), (class, text), (type, search), (tabindex, 1))) but I'm trying to keep the various element attributes in the template. When I try to bind with: searchBox -% doSearch _ instead of: searchBox - doSearch _ I get the following compile error: snippet/Ajax.scala:109: error: overloaded method value -% with alternatives ((scala.xml.NodeSeq) = scala.xml.Elem)net.liftweb.util.Helpers.FuncBindParam and (Option[scala.xml.Elem])net.liftweb.util.Helpers.FuncBindParam and (net.liftweb.common.Box[scala.xml.Elem])net.liftweb.util.Helpers.FuncBindParam and (scala.xml.Elem)net.liftweb.util.Helpers.FuncBindParam cannot be applied to ((scala.xml.NodeSeq) = scala.xml.NodeSeq) searchBox -% doSearch _ ^ one error found Between all the bind() and -()/-%() overloads and my general Scala / Lift ignorance, I can't understand what the right way to resolve this is. I think it has something to do with FocusOnLoad returning a NodeSeq (input/script/) vs. an Element, but I don't know where to go from here... Thanks in advance, - Luke -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.
[Lift] Re: Problem with FocusOnLoad and passing attributes through bind
On 22 feb., 04:12, Luke Nezda lne...@gmail.com wrote: Hello, I am new to Scala and Lift. I am having a problem using 2 features together which seem to work fine individually. Here's a simplified piece of the code: class Ajax { def someResult(q:String) = spansome results for query {q}.../ span // searchField closure def searchField(xhtml: NodeSeq): NodeSeq = { // build up an ajax text box def doSearch(msg: NodeSeq) = { // doesn't compile with bind: searchBox -% doSearch _ FocusOnLoad(SHtml.ajaxText(, q = SetHtml(resultz, someResult(q // compiles with bind: searchBox -% doSearch _ // SHtml.ajaxText(, q = SetHtml(resultz, someResult(q))) } // bind the view to the functionality bind(ajax, xhtml, searchBox - doSearch _ // doesn't compile if doSearch returns result of FocusOnLoad //searchBox -% doSearch _ ) } } and the template invocation: lift:surround with=default at=content lift:Ajax.searchField id_msgs=messages ajax:searchBox class=text type=search tabindex=1 / hr class=space/ div id=resultz/div div id=messages/div /lift:Ajax.searchField /lift:surround My goal is an Ajax-enabled text input that gets focus when the page loads and has various attributes of the input element set. I realize I can use the SHtml.ajaxText variant that takes attribute-value pairs, as in: FocusOnLoad(SHtml.ajaxText(, q = SetHtml(resultz, Yawni.query(q)), (class, text), (type, search), (tabindex, 1))) but I'm trying to keep the various element attributes in the template. When I try to bind with: searchBox -% doSearch _ instead of: searchBox - doSearch _ I get the following compile error: snippet/Ajax.scala:109: error: overloaded method value -% with alternatives ((scala.xml.NodeSeq) = scala.xml.Elem)net.liftweb.util.Helpers.FuncBindParam and (Option[scala.xml.Elem])net.liftweb.util.Helpers.FuncBindParam and (net.liftweb.common.Box[scala.xml.Elem])net.liftweb.util.Helpers.FuncBindPa ram and (scala.xml.Elem)net.liftweb.util.Helpers.FuncBindParam cannot be applied to ((scala.xml.NodeSeq) = scala.xml.NodeSeq) searchBox -% doSearch _ ^ one error found Why your doSearch function takes a msg parameter? ... it doesn't seam to use it. doSearch _ is a partially applied function and acts as a (NodeSeq) = NodeSeq however -% has only a definition like: def -%(in: NodeSeq = Elem) while - also has def -(in: NodeSeq = NodeSeq) which is why you get the compile error. We should add the same definition for NodeSeq = NodeSeq You can simply say: searchBox -% doSearch and have def doSearch: NodeSeq = ... FocusOnLoad returns a NodeSeq because it returns a sequence of nodes which conceptually cannot be converted to an elem. You could try to have a Group(FocusOnLoad ...) ... but Group is a Node not an Elem. Between all the bind() and -()/-%() overloads and my general Scala / Lift ignorance, I can't understand what the right way to resolve this is. I think it has something to do with FocusOnLoad returning a NodeSeq (input/script/) vs. an Element, but I don't know where to go from here... Thanks in advance, - Luke -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.