forwarder / meteor-wizard

A wizard component for Autoform.
MIT License
67 stars 17 forks source link

How to initial data for update form? #70

Closed thearabbit closed 8 years ago

thearabbit commented 8 years ago

I would like to initial data for update form. I have 3 steps

// Template
{{> wizard id="productUpdate" steps=steps doc=data stepsTemplate="steps_bootstrap3" clearOnDestroy=true}}
------------
{{#autoForm id="generalStep" schema=step.schema doc=step.data}}......
{{#autoForm id="loanAmountStep" schema=step.schema doc=step.data}}......
{{#autoForm id="chargStep" schema=step.schema doc=step.data}}......

// Helper
Template.productUpdate.helpers({
    data: function () {
        var data = Collection.Product.findOne(this._id);
        return data;
    },
    steps: function () {
        return [
            {
                id: 'general',
                title: 'General',
                template: 'generalStep',
                formId: 'generalStep',
                schema: Schema.Product.general
            },
             ..............................

            {
                id: 'charge',
                title: 'Charge',
                template: 'chargStep',
                formId: 'chargStep',
                schema: Schema.Product.charge,
                onSubmit: function (data, wizard) {
                    var self = this;
                    var extend = _.extend(wizard.mergedData(), data);
                    // update doc
                }
            }
        ]
    }
});
Pagebakers commented 8 years ago

If it's an update form, you don't need to use step.data but you can just pass the document to the form.

thearabbit commented 8 years ago

pass the doc to main form or all step form

// Template
{{> wizard id="productUpdate" steps=steps doc=data.........

// JS
Template.productUpdate.helpers({
    data: function () {
        var data = Collection.Product.findOne(this._id);
        return data;
    },

// Step
{#autoForm id="generalStep" schema=step.schema}}......
{{#autoForm id="loanAmountStep" schema=step.schema}}......
{{#autoForm id="chargStep" schema=step.schema}}......
Pagebakers commented 8 years ago

No that's not gonna work, you can reuse the same doc for each step, but best would be to return the doc with only the fields used in the specific form.

{#autoForm id="generalStep" schema=step.schema doc=doc}}......
{{#autoForm id="loanAmountStep" schema=step.schema doc=doc}}......
{{#autoForm id="chargStep" schema=step.schema doc=doc}}......
thearabbit commented 8 years ago

It mean that don't pass doc to main for, but pass data to each step

// Template
{{> wizard id="productUpdate" steps=steps

// JS
Template.productUpdate.helpers({
 steps: function () {
        return [
            {
                id: 'general',
                title: 'General',
                template: 'generalStep',
                formId: 'generalStep',
                schema: Schema.Product.general,
                data: function () {
                    var data = Collection.Product.findOne(this._id);
                    return data;
                },
            },
             ..............................

            {
                id: 'charge',
                title: 'Charge',
                template: 'chargStep',
                formId: 'chargStep',
                schema: Schema.Product.charge,
                data: function () {
                    var data = Collection.Product.findOne(this._id);
                    return data;
                },
                onSubmit: function (data, wizard) {
                    var self = this;
                    var extend = _.extend(wizard.mergedData(), data);
                    // update doc
                }
            }
        ]
    }
Pagebakers commented 8 years ago

Yeah I get the idea, but that's not supported at this time. So you have to pass the doc directly to the autoform in your steps.

Pagebakers commented 8 years ago

If you read through the closed issues, there are some examples using an update/insert form.

thearabbit commented 8 years ago

Thanks, look great :+1:

thearabbit commented 8 years ago

But now it have problem when I submit update form. It don't get the new value on previous step (It still get the initial value). Please help me.