Browse Source

fixed a bug breaking callable defaults in forms

master
phryk 4 months ago
parent
commit
9b99401c4f
2 changed files with 1 additions and 7 deletions
  1. 1
    1
      poobrains/form/__init__.py
  2. 0
    6
      poobrains/form/fields.py

+ 1
- 1
poobrains/form/__init__.py View File

@@ -71,7 +71,7 @@ class BaseForm(poobrains.rendering.Renderable, metaclass=FormMeta):
71 71
                     value = getattr(attr, propname)
72 72
                     if not callable(value):
73 73
                         value = copy.deepcopy(value)
74
-                    elif propname in ('default', 'choices'):
74
+                    elif propname in ('default', 'choices', 'value'):
75 75
                         value = value() # handle arguments to Fields that are optionally callable; ex: Checkbox(default=lambda: bool(random.randint(0,1)))
76 76
                     kw[propname] = value
77 77
 

+ 0
- 6
poobrains/form/fields.py View File

@@ -80,9 +80,6 @@ class BaseField(object, metaclass=poobrains.helpers.MetaCompatibility):
80 80
         if not choices is None:
81 81
             self.choices = choices # leave choices of other __init__ intact. <- TODO: what other __init__? did i mean statically defined properties in subclasses?
82 82
 
83
-        #if callable(self.choices):
84
-        #    self.choices = self.choices()
85
-
86 83
 
87 84
         if not default is None:
88 85
             self.default = default
@@ -90,9 +87,6 @@ class BaseField(object, metaclass=poobrains.helpers.MetaCompatibility):
90 87
         if self.default is None and self.multi:
91 88
             self.default = []
92 89
 
93
-        #if callable(self.default):
94
-        #    self.default = self.default()
95
-
96 90
 
97 91
         if not value is None:
98 92
             self.value = value

Loading…
Cancel
Save