AmpersandJS / ampersand-form-view

Completely customizable form lib for bulletproof clientside forms.
MIT License
26 stars 20 forks source link

How can you handle nested model/state children? #22

Closed pgilad closed 9 years ago

cdaringe commented 9 years ago

@pgilad, can you be more specific?

pgilad commented 9 years ago

It's probably redundant by now, but my original question was how do you use ampersand-form-view with a model/state children and/or collections?

I'd love to see some examples, since most models are not flat.

Especially handling the submitCallback in order to re-apply the new data to the model (again with nested data as well)

cdaringe commented 9 years ago

right. currently it doesn't support additional props. your best bet at the time of writing is to use a standard &-View, then manage the FormView as a subview. In this regard, you can place state/collections to the top level view, and reference those props & collection from the subview. this is what the example shows. the top level view is in the FormView's closure, so you can ref it, e.g., using the example from the README:

var AwesomeFormView = View.extend({
    props: {
        a: 'state' // the state/model/collection you're interested in
    },
    template: '<div><p>App form</p><form data-hook="app-edit-form"></form></div>',
    render: function () {
        this.renderWithTemplate();
        this.form = new FormView({
            el: this.queryByHook('app-edit-form'),
            submitCallback: function (obj) {
                console.dir(this.parent.a); // and here it is
            },

i think. i haven't tested this :$

cdaringe commented 9 years ago

Let's get back in touch if further discussion is needed and hash it out!