[Grok-dev] modifying widget dynamically
Jens Adner
j.adner at fh-sm.de
Mon Mar 1 09:46:55 EST 2010
Hi grokkers,
my app is in production since 8 months and all works fine, thanks to the
developper team for the great job.
Now, I want to make my app nicer and need some help. I would like to
change the css style of some form elements und added this method to my
form class:
def setUpWidgets(self, ignore_request = False):
super(MyForm, self).setUpWidgets(ignore_request)
self.widgets['field1'].cssClass = 'type-text'
self.widgets['check-field1'].cssClass = 'type-check'
self.widgets['check-field2'].cssClass = 'type-check'
I use this cssClass attribut in the view to change the Layout:
<tal:block repeat="widget view/widgets">
...
<div tal:attributes="class widget/cssClass" class="type-text">
...
OK, works fine. But now, in case of an error after an user input, I want
to change the css style dynamically while running the view. So I tried
somethings like:
def setUpWidgets(self, ignore_request = False):
super(MyForm, self).setUpWidgets(ignore_request)
self.widgets['field1'].cssClass = 'type-text'
self.widgets['check-field1'].cssClass = 'type-check'
self.widgets['check-field2'].cssClass = 'type-check'
if self.widgets['field1'].error() != '':
self.widgets['field1'].cssClass += ' error'
But the cssClass attribut never change. I think this method will be run
just for the first time the class is instantiated. Or the .error()
function of the widgets works not in this way.
Can I access the attributes of the widgets in the view object?
Thanks!
Best regards
Jens
--
+++++ Jens Adner, Rechenzentrum der FH Schmalkalden +++++
+++++ Fon: +49 3683688 9201 Fax: +49 3683688 989201 +++++
More information about the Grok-dev
mailing list