[Twisted-web] athena widgets and IE

Jean-Paul Calderone exarkun at divmod.com
Wed Oct 11 07:31:46 CDT 2006

On Wed, 11 Oct 2006 12:35:42 +0200, Fabio Forno <fabio.forno at gmail.com> wrote:
>Hi, I've a problem with an athena widget and IE.
>I define a widget for a LiveFragment like this one:
>var Widgets = {};

Using a recent version of Nevow, you shouldn't need to define the Widgets
namespace explicitly.  Also, "Widgets" is a pretty vague name.  I'd suggest
picking something less likely to collide.

>Widgets.ChatWidget = Nevow.Athena.Widget.subclass('Widgets.ChatWidget');
>    function keyPressed (self, event) {
>        if(event.key()["string"] == "KEY_ENTER") {
>            text_area = window.document.getElementById("chat_area");
>            d = self.callRemote('got_text', text_area.value);
>            d.addCallback(self.text_sent);
>        }
>    }

It's better to not use getElementById.  Instead, make the chat area node
a child of the ChatWidget's node and find it either by class or using the
new Widget.nodeById method.

>Then in the xml template I try to get a reference to the just defined
>method in this way:
>widget = Nevow.Athena.Widget.get(
>            document.getElementById("athena:1");
>        );

Likewise, "athena:1" is an implementation detail, and you can't rely on
your widget getting id "1" all the time.  Instead, try using the
athena:handler feature:

    <div nevow:render="liveFragment">
          <athena:handler event="onkeypress" handler="keyPressed" />

>In firefox everything is ok, while in explorer 6.0 I get undefined.
>MOreover, in i.e. there is this oddity. if a loop on all the
>attributes of widgetwith for(var i in widget) , I get also the
>keyPressed method, but when I try to get it with widget[i], I keep
>having undefined as result.
>Any idea?

A difference here wouldn't surprise me.  Iteration in JavaScript is extremely
inconsistent, even within a single runtime.  I don't know of the /specific/
problem which causes the behavior you're describing above, and it may be
fixable, but it'd probably be better just to not rely on iteration.


More information about the Twisted-web mailing list