[Zope3-Users] z3c.form, style-attribute of TextWidget, TextAreaWidget

Andreas Reuleaux reuleaux at web.de
Thu Aug 30 08:50:16 EDT 2007


Given a simple interface IPerson with some TextLine (Text) fields

  class IPerson(Interface):
      """a person"""

      nachname = TextLine(
	  title=u"Nachname",
	  ...
	  )

      vorname = TextLine(
	  title=u"Vorname",
	  ...
	  )

      anrede = TextLine(
	  title=u"Anrede",
	  ...
	  )

      sonst = Text(
	  title=u'Sonstiges',
	  ...
	  )


I should be able to give the widgets some custom appearance by
not only appending to their klass-Attribute (w.addClass()) but also
by setting their style-Attribute (w.style) like this

  class PersonEditForm(subform.EditSubForm):
      fields=field.Fields(IPerson)
      prefix='person.edit'

      def updateWidgets(self):
	  super(PersonEditForm, self).updateWidgets()
	  sty={'anrede': u'width: 55px;',
	       'vorname': u'width: 105px;',
	       'nachname': u'width: 105px;',
	      }
	  for k in sty.keys():
	      w=self.widgets.get(k)
	      w.style=sty[k]
	      w.addClass("in")

The widgets do have a style-Attribute after all and this used
to work in formlib. - However this has no effect when rendering:

   <input type="text" id="person-edit-widgets-nachname"
	  name="person.edit.widgets.nachname"
	  class="textWidget textline-field in" 
          value="..."/>

   ...

There is just no style attribute. - I would expect something like:

  <input type="text" id="person-edit-widgets-nachname"
       name="person.edit.widgets.nachname"
       class="textWidget textline-field in"
       style="width: 105px;" value="..." />

Having a look at text_input.pt in my z3c.form egg shows why: style is
just ignored there. If I add the style attribute there, everything
works fine:

reuleaux at softland(~/z3eggs/z3c.form-1.6.0-py2.4.egg/z3c/form/browser)$ diff -u text_input.pt.ORIG text_input.pt
--- text_input.pt.ORIG  2007-08-30 01:05:52.000000000 +0200
+++ text_input.pt       2007-08-30 13:59:30.000000000 +0200
@@ -26,4 +26,5 @@
                        accesskey view/accesskey;
                        onselect view/onselect;
                        size view/size;
-                       maxlength view/maxlength" />
+                       maxlength view/maxlength;
+                       style view/style" />
reuleaux at softland(~/z3eggs/z3c.form-1.6.0-py2.4.egg/z3c/form/browser)$

Is there any particular reason why this style attribute was left out or is this just a bug?
- The same for textarea_input.pt

-Andreas


More information about the Zope3-users mailing list