web/formfields.py
changeset 4252 6c4f109c2b03
parent 4251 3c6569be1f86
parent 4215 9fbc39453012
child 4269 da0d254f2eb0
equal deleted inserted replaced
4251:3c6569be1f86 4252:6c4f109c2b03
     1 """field classes for form construction
     1 """field classes for form construction
     2 
     2 
     3 :organization: Logilab
     3 :organization: Logilab
     4 :copyright: 2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
     4 :copyright: 2009-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
     5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
     5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
     6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
     6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
     7 """
     7 """
     8 __docformat__ = "restructuredtext en"
     8 __docformat__ = "restructuredtext en"
     9 
     9 
   378                     yield field, value
   378                     yield field, value
   379 
   379 
   380 
   380 
   381 class StringField(Field):
   381 class StringField(Field):
   382     widget = TextArea
   382     widget = TextArea
       
   383     size = 45
   383 
   384 
   384     def __init__(self, name=None, max_length=None, **kwargs):
   385     def __init__(self, name=None, max_length=None, **kwargs):
   385         self.max_length = max_length # must be set before super call
   386         self.max_length = max_length # must be set before super call
   386         super(StringField, self).__init__(name=name, **kwargs)
   387         super(StringField, self).__init__(name=name, **kwargs)
   387 
   388 
   398         elif isinstance(self.widget, TextInput):
   399         elif isinstance(self.widget, TextInput):
   399             self.init_text_input(self.widget)
   400             self.init_text_input(self.widget)
   400 
   401 
   401     def init_text_input(self, widget):
   402     def init_text_input(self, widget):
   402         if self.max_length:
   403         if self.max_length:
   403             widget.attrs.setdefault('size', min(45, self.max_length))
   404             widget.attrs.setdefault('size', min(self.size, self.max_length))
   404             widget.attrs.setdefault('maxlength', self.max_length)
   405             widget.attrs.setdefault('maxlength', self.max_length)
   405 
   406 
   406     def init_text_area(self, widget):
   407     def init_text_area(self, widget):
   407         if self.max_length < 513:
   408         if self.max_length < 513:
   408             widget.attrs.setdefault('cols', 60)
   409             widget.attrs.setdefault('cols', 60)