[Seaside][SeasiedAsync] Capturing events

Michel Bany m.bany at wanadoo.fr
Fri Mar 31 08:42:16 UTC 2006


The other day a customer of mine came with an interesting request.
They wanted to know what field on the page had the focus just before
a button was clicked and a new component called.
Their idea was to restore the focus to that field when returning from the
called component, possibly with the cursor placed at the right position.

After some discussion, we thought of reusing the SeasideAsync framework
and came with a design where any javascript event can trigger a callback.

It works with both "canvas" and "classic" Seaside with the following api :
(pardon the possible mistakes in these examples)

    html onFocusCallback: [:event :renderer | lastFocus := 'field-1'].
    html textInputWithValue: field1 callback: [:v | field1 := v].

    html textInput
        value: field1;
        onFocusCallback: [:event :renderer | lastFocus := 'field-1'];
        callback: [:v | field1 := v].

The above examples are capturing the "focus" javascript event, but this
should also support any other javascript event. The javascript event is
turned into an instance of WALiveEvent with a bunch of properties,
and the event object is passed to the callback. A renderer is also made
available so that the application can modify portions of the page.

This is available at squeaksource.com/Seaside as SeasideAsync-mb.31
and requires Seaside 2.6b1. This is pretty much untested, and this is the
reason for this post. I would appreciate if interested people would give it
a try and let me know how it goes.

Meanwhile, I'll have a look to the cursor issue ...


More information about the Seaside mailing list