Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update mode example #9

Closed
aposidelov opened this issue Oct 17, 2016 · 5 comments
Closed

Update mode example #9

aposidelov opened this issue Oct 17, 2016 · 5 comments

Comments

@aposidelov
Copy link

aposidelov commented Oct 17, 2016

Here is an example how to implement autoform with update mode & upload field. Critical place is that autoform should be wrapped in {{#if Template.subscriptionsReady }} which makes sure that template level subscription is ready. Without it the picture preview won't be shown. Also to make upper {{#if}} to be worked the template level subscription should be used (this.subscribe instead of Meteor.subscribe)

EditProductForm.js

Template.EditProductForm.onCreated(function() {    
    var self = this;        
    self.autorun(function() {   
        var id = FlowRouter.getParam('id');            
        self.subscribe('products.one', id);        
    });
});

Template.EditProductForm.helpers({
    getProduct() {
        var id = FlowRouter.getParam('id');
        var product = ProductsCollection.findOne(id);        
        return product;
    }
});

EditProductForm.html

<template name="EditProductForm">
    <div class="container">
        <div class="row">       
            {{#if Template.subscriptionsReady }}    
                {{#autoForm type="update" doc=getProduct collection=ProductsCollection  id="EditProductForm"}}
                    {{> afQuickField name='title'}}
                    {{> afQuickField name='desc'}}
                    {{> afQuickField name='priceAmount'}}
                    {{> afQuickField name='tags'}}
                    {{> afQuickField name='picture'}}     
                    <button type="submit" class="btn btn-primary btn-update">Update</button>
                    <button type="submit" class="btn btn-primary btn-delete">Delete</button>
                {{/autoForm}}
            {{/if}}
        </div>
    </div>
</template>

and server-side code

Meteor.publish('products.one', function(id) {       
    var product = ProductsCollection.find({_id: id});   
    var pictureId = product.fetch()[0].picture; 
    return [product, Images.find({_id: pictureId}).cursor]; 
});
@aposidelov aposidelov changed the title Autoform update mode example Update mode example Oct 17, 2016
@dr-dimitru
Copy link
Member

HI @aposidelov ,

Looks good to me. What should I do with it?

@aposidelov
Copy link
Author

just mark it as an example or link to it in the package description section where insert mode is described

@dr-dimitru
Copy link
Member

@aposidelov okay, now it's clear.
Would you send a PR?

@aposidelov
Copy link
Author

#10

dr-dimitru added a commit that referenced this issue Dec 16, 2016
 - Docs update, closing #9 and #10
 - Dependencies update
@dr-dimitru
Copy link
Member

Thank you for contribution.
Ans sorry for delay with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants