To observe key input?

7 views
Skip to first unread message

etnt

unread,
Jun 23, 2009, 9:45:47 AM6/23/09
to Nitrogen Web Framework for Erlang
Hi folks!

I'm implementing something similar to Google suggest.

I want to send the content of a textarea at 'keyup' , which
is easy, but i wonder if it is possible to tell Nitrogen to wait
a short while for another (possible) keyup, just to optimize
for quick typers ?

I played with the delay parameter but it doesn't seem to solve this.

I include the code below if anyone want to experiment.

--Tobbe

-module (web_query).
-export ([main/0, title/0, body/0, event/1]).
-include_lib ("nitrogen/include/wf.inc").
main() ->
#template {file="./wwwroot/template.html"}.
title() -> "Test".
body() ->
B = #panel{body = [#panel{class = "queries", id=qfeedback},
#panel{class = "queries", body=[#textbox
{id=qinput}]}]},
wf:wire(qinput, #event {type=keyup, delay=100,
postback=keyup}),
wf:render([B]).

event(keyup) ->
[Input] = wf:q(qinput),
io:format("Got keyup: ~p~n",[Input]).

Tom McNulty

unread,
Jun 23, 2009, 2:04:59 PM6/23/09
to nitro...@googlegroups.com


- Tom

On 23-Jun-09, at 7:45 AM, etnt wrote:

>
> Hi folks!
>
> I'm implementing something similar to Google suggest.
>
> I want to send the content of a textarea at 'keyup' , which
> is easy, but i wonder if it is possible to tell Nitrogen to wait
> a short while for another (possible) keyup, just to optimize
> for quick typers ?
>
> I played with the delay parameter but it doesn't seem to solve this.

With a delay, are the events just being stacked, delay ms apart?

etnt

unread,
Jun 24, 2009, 2:02:43 AM6/24/09
to Nitrogen Web Framework for Erlang


On Jun 23, 8:04 pm, Tom McNulty <tom.mcnu...@cetiforge.com> wrote:
> - Tom
>
> On 23-Jun-09, at 7:45 AM, etnt wrote:
>
>
>
> > Hi folks!
>
> > I'm implementing something similar to Google suggest.
>
> > I want to send the content of a textarea at 'keyup' , which
> > is easy,  but i wonder if it is possible to tell Nitrogen to wait
> > a short while for another (possible) keyup, just to optimize
> > for quick typers ?
>
> > I played with the delay parameter but it doesn't seem to solve this.
>
> With a delay, are the events just being stacked, delay ms apart?

Yes, it seems so.
Not sure what delay is supposed to do?

--Tobbe

Tom McNulty

unread,
Jun 24, 2009, 4:30:22 PM6/24/09
to nitro...@googlegroups.com
From looking at the source, delay is actually ignored unless it's a
timer event or a continuation. So it won't have any effect here. To
enable this functionality we need some more framework side machinery.
Keeping the existing interface, the presence of a delay field should
automatically start a timer. Adding a "coalesce" field could toggle
between stacked events, and coalesced events (as needed in the
aforementioned problem). I think the framework should provide this
feature transparently, alternatively it could be achieved with a more
powerful client-side api.

In the mean time, my solution (hack) would be doing this with client-
side js, and sending an ajax request to a URL which bypasses nitrogen
altogether (by altering loop()).

Rusty will your next updates include a client-side api?

Slightly off topic, but one feature I'd really like to have, is the
ability to chain multiple hooks to nitrogen's ajax events. JQuery
supports this in it's comet model, allowing you to hook into various
stages of the request. These hook's could be p nitrogens laced in
existing event handlers.

Why is this useful?

This would enable users to set condition-guards, and pre-processing
filters on the data before it's actually sent. If any filter returns
false, the event is squelched, otherwise it passes data on to the next
hook/stage.

some pseudo code:

filter1(data) {
data2 = data.uppercase(),
return data2;}

filter2(data) {
return data unless moon_is_blue else false;
}


- Tom
Reply all
Reply to author
Forward
0 new messages