[formfields] set a reasonable minimal minimum length to input/text, also set the max length if applicable (closes #344538) stable
authorAurelien Campeas <aurelien.campeas@logilab.fr>
Thu, 09 Jul 2009 12:06:14 +0200
branchstable
changeset 2344 22b5ea0679ed
parent 2343 5f5259e838cb
child 2345 16e3d0e47ee6
[formfields] set a reasonable minimal minimum length to input/text, also set the max length if applicable (closes #344538)
web/formfields.py
--- a/web/formfields.py	Thu Jul 09 11:55:47 2009 +0200
+++ b/web/formfields.py	Thu Jul 09 12:06:14 2009 +0200
@@ -203,6 +203,11 @@
                 widget = Select()
             elif self.max_length and self.max_length < 257:
                 widget = TextInput()
+                maxlength = self.max_length or 45
+                widget.attrs.setdefault('size', min(45, maxlength))
+                if self.max_length:
+                    widget.attrs.setdefault('maxlength', self.max_length)
+
         super(StringField, self).init_widget(widget)
         if isinstance(self.widget, TextArea):
             self.init_text_area(self.widget)