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 <[email protected]> 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 <[email protected]> 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 <[email protected]> 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 <[email protected]> wrote:
>
> > > > On 22 feb., 04:12, Luke Nezda <[email protected]> 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) = <span>some 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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/liftweb?hl=en.