diff --git a/tailbone/forms2/core.py b/tailbone/forms2/core.py index c1cf9782..3dcd46e3 100644 --- a/tailbone/forms2/core.py +++ b/tailbone/forms2/core.py @@ -177,8 +177,8 @@ class Form(object): """ def __init__(self, fields=None, schema=None, request=None, readonly=False, readonly_fields=[], - model_instance=None, model_class=None, nodes={}, enums={}, labels={}, renderers={}, widgets={}, - action_url=None, cancel_url=None): + model_instance=None, model_class=None, nodes={}, enums={}, labels={}, renderers={}, + widgets={}, defaults={}, action_url=None, cancel_url=None): self.fields = list(fields) if fields is not None else None self.schema = schema @@ -196,6 +196,7 @@ class Form(object): self.labels = labels or {} self.renderers = renderers or {} self.widgets = widgets or {} + self.defaults = defaults or {} self.action_url = action_url self.cancel_url = cancel_url @@ -265,6 +266,11 @@ class Form(object): if key in schema: schema[key].widget = widget + # apply any default values + for key, default in self.defaults.items(): + if key in schema: + schema[key].default = default + self.schema = schema return self.schema @@ -330,7 +336,7 @@ class Form(object): """ Set the default value for a given field. """ - raise NotImplementedError # TODO + self.defaults[key] = value def render(self, template=None, **kwargs): if not template: