Skip to content

Commit

Permalink
Merge pull request #1 from sonechiman/master
Browse files Browse the repository at this point in the history
Add nested form
  • Loading branch information
Daniel Perez committed Apr 4, 2016
2 parents a52bddd + 2ae3de6 commit 3a36b38
Show file tree
Hide file tree
Showing 10 changed files with 236 additions and 41 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ MyInput.defaultTag = 'my-tag'
riotForm.inputFactory.register(MyInput)
```

or with ES5
or with ES6

```javascript
// ES6
Expand Down
164 changes: 130 additions & 34 deletions dist/riot-form.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/riot-form.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/riot-form.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/riot-form.min.js.map

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion lib/form-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default class FormBuilder {
assert(name, 'You must provide a name for the form')
this._model = {}
this._inputs = {}
this._forms = {}
this._name = name
}

Expand All @@ -17,7 +18,6 @@ export default class FormBuilder {
input = inputFactory.create(input)
}
assert(input.name, 'You must provide an input name')
input.formName = this._name
this._inputs[input.name] = input
return this
}
Expand All @@ -29,6 +29,13 @@ export default class FormBuilder {
return this
}

addNestedForm(form) {
assert(form instanceof Form, 'A form must be instance of Form')
form.name = this._name + '.' + form.name
this._forms[form.name] = form
return this
}

setModel(model) {
this._model = model
return this
Expand All @@ -38,6 +45,7 @@ export default class FormBuilder {
return new Form(assign({
model: this._model,
inputs: this._inputs,
forms: this._forms,
name: this._name
}, config))
}
Expand Down
Loading

0 comments on commit 3a36b38

Please sign in to comment.