Sent from my cell
Diego
On Jul 30, 2011 7:10 AM, "Richard Dallaway" <ric...@dallaway.com> wrote:
>
> A beautiful sunny Saturday, so what better way to spend it then with the REPL...
>
> I found a way to achieve the delay call using the wonder that is CSS Selector Transforms, and ignoring the RESTHelper approach. It sort of feels right, and in case anyone else needs this kind of thing, here's what I have...
>
> Assuming a function in Javascript called "delay" which is:
>
> // See: http://stackoverflow.com/questions/1909441/jquery-keyup-delay
> var delay = (function(){
> var timer = 0;
> return function(callback, ms){
> clearTimeout(timer);
> timer = setTimeout(callback, ms);
> };
> })();
>
> I can take the ajaxCall and wrap it with the delay JavaScript function:
>
> def render = "#sentence [onkeyup]" #> SHtml.ajaxCall(JsRaw("$('#sentence').val()"), tokenize _) andThen
> "#sentence [onkeyup]" #> delayWrap _ andThen
> "#words" #> WiringUI.asText(words)
>
> private def delayWrap(ns: NodeSeq): Text = Text("delay(function(){" + ns \\ "@onkeyup" + ";}, 200);")
>
> There might be a nicer way to construct the JavaScript, but this appears to work for me.
It looks great, thanks for sharing!
>
> Richard
>
>
>
> On 29 July 2011 16:58, Richard Dallaway <ric...@dallaway.com> wrote:
>>
>> I'd like to make use of onkeyup to send some data to the server, but I'd like to add a delay to avoid every single keystroke causing an ajax call. The JavaScript side looks ok (via http://stackoverflow.com/questions/1909441/jquery-keyup-delay), but I'm having difficulties mixing it into Lift.
>>
>> I'm using 2.4-M3 and Scala 2.8, and there's WiringUI involved.
>>
>> I started with a...
>>
>> "theInput [onkeyup]" #> SHtml.ajaxCall(JsRaw("this.value"), updateCell _)
>>
>> ...but I can't see how to wrap SHtml.ajaxCall with a delay on the client-side.
>>
>> As an alternative approach I've tried binding to the onkeyup event in JavaScript, and then doing a REST POST of the value to the server, where it updates the Cell. This almost works, except the cell change doesn't appear to be propagated to the web browser until something else happens (page refresh, or in an app with comet components it seems to happen after about 2 minutes).
>>
>> I have a demo on github of this REST-based approach, but clearly there's a gap in my understanding of how Wiring and Rest work together.
>>
>> The demo has a text field, and as you type in, it posts your words to the server where they are split into individual words and a ValueCell[List[String]) is updated.
>>
>> https://github.com/d6y/delay_keyup_via_list_rest_wiring
>>
>> The two files are the index and HelloWorld:
>>
>> https://github.com/d6y/delay_keyup_via_list_rest_wiring/blob/master/src/main/webapp/index.html
>> https://github.com/d6y/delay_keyup_via_list_rest_wiring/blob/master/src/main/scala/code/snippet/HelloWorld.scala
>>
>> Suggestions much appreciated
>> Richard
>>
>
> --
> 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.
[snip]