web/formfields.py
changeset 9718 927d035b6921
parent 9444 6012cf57f48e
child 9821 2077c8da1893
--- a/web/formfields.py	Mon Apr 14 23:00:19 2014 +0200
+++ b/web/formfields.py	Tue Jan 07 15:10:57 2014 +0100
@@ -529,6 +529,7 @@
     """
     widget = fw.TextArea
     size = 45
+    placeholder = None
 
     def __init__(self, name=None, max_length=None, **kwargs):
         self.max_length = max_length # must be set before super call
@@ -547,6 +548,9 @@
         elif isinstance(self.widget, fw.TextInput):
             self.init_text_input(self.widget)
 
+        if self.placeholder:
+            self.widget.attrs.setdefault('placeholder', self.placeholder)
+
     def init_text_input(self, widget):
         if self.max_length:
             widget.attrs.setdefault('size', min(self.size, self.max_length))
@@ -557,6 +561,11 @@
             widget.attrs.setdefault('cols', 60)
             widget.attrs.setdefault('rows', 5)
 
+    def set_placeholder(self, placeholder):
+        self.placeholder = placeholder
+        if self.widget and self.placeholder:
+            self.widget.attrs.setdefault('placeholder', self.placeholder)
+
 
 class PasswordField(StringField):
     """Use this field to edit password (`Password` yams type, encoded python