Sending keypresses to Nitrogen - Is this possible?

33 views
Skip to first unread message

hanrelan

unread,
Feb 18, 2010, 6:49:11 PM2/18/10
to Nitrogen Web Framework for Erlang
Hi,

I'm trying to send a keypress postback event from client to server.
The keypress event has to be defined on 'document', and I can get it
to popup an alert with the character when a key is pressed using pure
javascript. How do I get it to send this information (the character
has to be extracted from the event) back to Nitrogen in a postback? Is
this possible with the current framework?

Thanks,
Rohan

Rusty Klophaus

unread,
Feb 21, 2010, 11:08:23 AM2/21/10
to nitro...@googlegroups.com
Hi Rohan,

This is not easy to do in the master branch of master branch of Nitrogen.

It is easy in the experimental branch, however, with the use of the #api {} action. 

First, wire up a Javascript API in your Erlang module like this:

wf:wire(#api { name="gotkey", tag=gotkey }).

Then, in Javascript on the page itself, call the method via Javascript. This will initiate a Nitrogen postback to your page.

document.gotkey(KeyCode);

Finally, back on the page module, define the following function:

api_event(gotkey, KeyCode) ->
  ...,
  ok.

For more information about the #api{} event, run the Quickstart project in the experimental branch, and checkout the Javascript API sample page: http://localhost:8000/web/samples/api

Best,
Rusty


--
You received this message because you are subscribed to the Google Groups "Nitrogen Web Framework for Erlang" group.
To post to this group, send email to nitro...@googlegroups.com.
To unsubscribe from this group, send email to nitrogenweb...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nitrogenweb?hl=en.


hanrelan

unread,
Feb 22, 2010, 3:57:11 PM2/22/10
to Nitrogen Web Framework for Erlang
Thanks Rusty.
I've tried to get the experimental branch running, and the quickstart
works, but when I run my own app, all I get are blank pages.
The server isn't throwing an error, but every page I navigate to is
just empty.

I changed the include_lib directives at the top of every page from
"nitrogen/include/wf.inc" to "nitrogen/apps/nitrogen/include/wf.inc",
which made it compile successfully, but can't figure out why it
doesn't error out when I make a request.

Any ideas?

> > nitrogenweb...@googlegroups.com<nitrogenweb%2Bunsubscribe@googlegr oups.com>

hanrelan

unread,
Feb 22, 2010, 5:26:22 PM2/22/10
to Nitrogen Web Framework for Erlang
Ok scratch that. I figured out how to get it working. Basically I
copied the quickstart_app.erl application file and made some changes
so that it would start my app instead of quickstart.

However, it looks the experimental branch breaks compatibility with
the master branch around the comet implementation, so I'd like to
continue using master.

How hard would it be for me to merge the #api stuff into my local
master? Does it just involve copying over action_api.erl and the
corresponding records and Javascript, or does this use some major new
stuff in experimental?

Torbjörn Törnkvist

unread,
Feb 23, 2010, 3:54:53 AM2/23/10
to nitro...@googlegroups.com
What about:

      wf:wire(Id, #event {type=keyup, postback=keyup}),

Where Id is the id of e.g a textarea element.

Then, take care of the event:

    event(keyup) ->                                                                                                                                                                                                                   
        [Input] = wf:q(Id),
        ...

--Tobbe

2010/2/19 hanrelan <hanr...@gmail.com>
--
You received this message because you are subscribed to the Google Groups "Nitrogen Web Framework for Erlang" group.
To post to this group, send email to nitro...@googlegroups.com.
To unsubscribe from this group, send email to nitrogenweb...@googlegroups.com.

hanrelan

unread,
Feb 23, 2010, 12:03:43 PM2/23/10
to Nitrogen Web Framework for Erlang
Unfortunately, I'm trying to capture keypresses that aren't occurring
in a textarea. The keypress handler needs to be set on the document
object itself

On Feb 23, 3:54 am, Torbjörn Törnkvist <to...@tornkvist.org> wrote:
> What about:
>
>       wf:wire(Id, #event {type=keyup, postback=keyup}),
>
> Where Id is the id of e.g a textarea element.
>
> Then, take care of the event:
>
>     event(keyup) ->
>
>         [Input] = wf:q(Id),
>         ...
>
> --Tobbe
>

> 2010/2/19 hanrelan <hanre...@gmail.com>


>
>
>
> > Hi,
>
> > I'm trying to send a keypress postback event from client to server.
> > The keypress event has to be defined on 'document', and I can get it
> > to popup an alert with the character when a key is pressed using pure
> > javascript. How do I get it to send this information (the character
> > has to be extracted from the event) back to Nitrogen in a postback? Is
> > this possible with the current framework?
>
> > Thanks,
> > Rohan
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Nitrogen Web Framework for Erlang" group.
> > To post to this group, send email to nitro...@googlegroups.com.
> > To unsubscribe from this group, send email to

> > nitrogenweb...@googlegroups.com<nitrogenweb%2Bunsubscribe@googlegr oups.com>

Reply all
Reply to author
Forward
0 new messages