[Twisted-web] DOM manipulation in an athena widget

Jean-Paul Calderone exarkun at divmod.com
Sat Sep 30 18:36:28 CDT 2006


On Sun, 01 Oct 2006 00:14:14 +0100, Phil Mayers <p.mayers at imperial.ac.uk> wrote:
> [snip]
>
>db.Record.methods(
>   function editField(self, node, event) {
>     if (node.inEdit) return false;
>     /* make the textbox */
>     var tb = INPUT({'type': 'text', 'value': scrapeText(node)});
>     /* swap the span for a textbox */
>     replaceChildNodes(
>       getElementsByTagAndClassName('span', null, node)[0], tb
>     );
>
>     /* THIS FAILS */
>     connect(tb, 'onblur', self.saveField);
>
>     return false;
>   });
>
>The nevow debug console thing logs "self has no properties" - what is self 
>in this context of a widget method/event call? Why does it have no 
>properties?

Athena doesn't automatically bind methods to instances, unfortunately.  This
means when the onblur handler is invoked, saveField will be invoked without
any reference to the widget it came from.  Athena will let this happen, but
self won't be bound properly.  Try connecting this instead:

    function() { self.saveField(); }

Jean-Paul



More information about the Twisted-web mailing list