Skip to content

Commit

Permalink
Let the user choose the name of the data object for the form.
Browse files Browse the repository at this point in the history
  • Loading branch information
ernestoalejo committed Feb 10, 2013
1 parent eaa20fe commit fa25034
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions ngforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
class Form(object):
field_values = {}

def __init__(self, form_name='f', submit_func='submit', try_submit_func=''):
def __init__(self, form_name='f', submit_func='submit', try_submit_func='',
data_obj='data'):
self.form_name = form_name
self.submit_func = submit_func
self.try_submit_func = try_submit_func
self.data_obj = data_obj

def build(self):
fields = ''.join([f.build(self) for f in self.fields])
Expand Down Expand Up @@ -220,7 +222,7 @@ def build(self, form):
"name": self.id,
"placeholder": self.placeholder,
"class": ' '.join(self.cls),
"ng-model": 'data.%s' % self.id,
"ng-model": '%s.%s' % (form.data_obj, self.id),
}

(at, tmpl) = super(InputField, self).build(form)
Expand All @@ -246,7 +248,7 @@ def build(self, form):
"name": self.id,
"placeholder": self.placeholder,
"class": ' '.join(self.cls),
"ng-model": 'data.%s' % self.id,
"ng-model": '%s.%s' % (form.data_obj, self.id),
"rows": self.rows,
}

Expand Down

0 comments on commit fa25034

Please sign in to comment.