[Twisted-web] Formless disabling widget

Steven Holmes steg at linuxops.net
Wed Jan 25 10:26:59 MST 2006

On 25 Jan 2006, at 09:24, Suha Onay wrote:

> Hi,
> Mike is right. I want my widgets to be disabled by setting an  
> attribute 'disabled':
> <input disabled type="text" name="xxx" /> or <input type="checkbox"  
> name="foo" disabled="1" />
> Is it possible without writing custom render methods to my own  
> widgets?
> I use my own widgets to overwrite only the error messages  
> ("requiredFailMessage") of the annotate classes.
> If it is not possible with webform rendering, Steven I think I need  
> your post :)
> Thanks

As far as I know, it is impossible to add custom attributes without
writing your own renderer. This is unfortunate because it means you
can end up with a bunch of very similar rendering classes. (Although
if you look at what happens to keyword arguments in annotate.Typed,
you'll see it'd be reasonably easy to pass in custom attribute
arguments and access them in your custom renderer).

An alternative, if you don't mind running with a customized formless,
is altering annotate.py so that your Typed accepts a "disabled"
argument. You could then alter webform.py so the TypedRenderers there
check this value and if appropriate add the attribute in.

This isn't a brilliant solution either though, as I can't see a
reasonable way to do this in one place for all of the
TypedRenderers. You'd need to alter each of them that you wanted to be
able to use the attribute. Of course, when you decide to add another
custom attribute, you need to do the same all over again. :)

Perhaps it would be nice if formless had a way for you to tell it to
add particular attributes... a custom_attributes dictionary to
annotate.Typed for instance. It'd be very handy in situations like
this, but could be abused to go against formless's idea of seperating
the argument types from the way they're rendered. Comments on this
would be appreciated.

Cheers and hope this helps,

Steven Holmes

More information about the Twisted-web mailing list