Giter Club home page Giter Club logo

Comments (7)

aldeed avatar aldeed commented on May 11, 2024

Just create an AutoForm instance on the client, passing in the Collection2 as the only argument to the constructor. Then attach all your hooks to the AutoForm and use the AutoForm for your autoForm helper's schema attribute.

On Thu, Dec 12, 2013 at 3:59 AM, kevohagan [email protected]
wrote:

Or from a collection2 how can i define a autoform instance to use it's hooks system?
i looked at the autoform example but i dont get how it defines the documents.hooks since its a collectin2 instance and shouldnt be able to use the callbacks/hooks.

Thanks a lot 👍

Reply to this email directly or view it on GitHub:
#50

from meteor-autoform.

kevohagan avatar kevohagan commented on May 11, 2024

It's strange because in your example you dont pass the Collection2 Documents in an instance of AutoForm to get your hooks.

I define a collection2 Workshops

That is what im doing on the client :

 {{#autoForm schema=WorkshopsForm id="insertWorkshopForm"}}

with

 WorkshopsForm = new AutoForm(Workshops);

         WorkshopsForm.hooks({
            insert: function(error, result) {
                if (error) {
                    console.log("Insert Error:", error);
                } else {
                    alert("Inserted!");
                    console.log("Insert Result:", result);
                }
            },
            update: function(error) {
                if (error) {
                    console.log("Update Error:", error);
                } else {
                    alert("Updated!");
                }
            },
            remove: function(error) {
                console.log("Remove Error:", error);
            }
        });

and i get Exception from Deps recompute: TypeError: Cannot call method 'simpleSchema' of undefined

im definitely missing something simple

from meteor-autoform.

kevohagan avatar kevohagan commented on May 11, 2024

If i define it like

 {{#autoForm schema=Workshops id="insertWorkshopForm"}}

with



         Workshops.hooks({
            insert: function(error, result) {
                if (error) {
                    console.log("Insert Error:", error);
                } else {
                    alert("Inserted!");
                    console.log("Insert Result:", result);
                }
            },
            update: function(error) {
                if (error) {
                    console.log("Update Error:", error);
                } else {
                    alert("Updated!");
                }
            },
            remove: function(error) {
                console.log("Remove Error:", error);
            }
        });

i get Exception from Deps afterFlush function: TypeError: Object [object Object] has no method 'hooks'

but if i call it with Workshops.callbacks it works!

but console returns

myCollection2.callbacks is deprecated; use myCollection2.hooks 

weird

from meteor-autoform.

aldeed avatar aldeed commented on May 11, 2024

Maybe a bug. I won't be around a computer for a couple days, but I'll test as soon as I can.

On Fri, Dec 13, 2013 at 11:44 AM, kevohagan [email protected]
wrote:

If i define it like

 {{#autoForm schema=Workshops id="insertWorkshopForm"}}

with

         Workshops.hooks({
            insert: function(error, result) {
                if (error) {
                    console.log("Insert Error:", error);
                } else {
                    alert("Inserted!");
                    console.log("Insert Result:", result);
                }
            },
            update: function(error) {
                if (error) {
                    console.log("Update Error:", error);
                } else {
                    alert("Updated!");
                }
            },
            remove: function(error) {
                console.log("Remove Error:", error);
            }
        });

i get Exception from Deps afterFlush function: TypeError: Object [object Object] has no method 'hooks'
but if i call it with Workshops.callbacks it works!
but console returns

myCollection2.callbacks is deprecated; use myCollection2.hooks 

weird

Reply to this email directly or view it on GitHub:
#50 (comment)

from meteor-autoform.

chrisbutler avatar chrisbutler commented on May 11, 2024

@kevohagan i was stumped by the same issue for a little while. your original example was 99% there, you just forgot quotes around schema='WorkshopsForm'

from meteor-autoform.

aldeed avatar aldeed commented on May 11, 2024

Did you resolve this? Let me clarify a few things:

  • You can pass either a Collection2 instance or an AutoForm instance as the schema. BUT if you want to add hooks, you need to use an AutoForm instance (wrapping the C2) because you can't add the hooks to a Collection2.
  • Even if you don't need hooks, you'll get a little better performance by using AutoForm wrapper instead of passing the C2 directly. Being able to pass the C2 directly is for backwards compatibility and simplicity, but isn't the recommended way. (Docs should probably be updated a bit.)
  • As far as how to pass the C2/AF instance to the helper, you can do so either as a string or as another helper. If you use a string, it looks in the window scope for an object with that name. Otherwise by using a helper you are directly binding. Again, using the helper is the recommended way because you'll get better performance and you then could use your own namespace, but passing the string name is easier to understand and less code.

In the specific issue above, as @chrisbutler mentioned, you can either add quotes around WorkshopsForm or you can make a WorkshopsForm helper that returns the WorkshopsForm object, like this:

Template.myTemplateName.WorkshopsForm = function () {
    return WorkshopsForm;
};

from meteor-autoform.

kevohagan avatar kevohagan commented on May 11, 2024

Yes Perfect resolved it!

Much clearer now ;) . For the record that is what i did :


Template.new_workshop.newWorkshopsForm = function () {


 newWorkshopsForm = new AutoForm(Workshops);

         newWorkshopsForm.callbacks({
            insert: function(error, result) {
                if (error) {
                    console.log("Insert Error:", error);
                } else {
                    alert("Inserted!");
                    console.log("Insert Result:", result);
                }
            },
            update: function(error) {
                if (error) {
                    console.log("Update Error:", error);
                } else {
                    alert("Updated!");
                }
            },
            remove: function(error) {
                console.log("Remove Error:", error);
            }
        });

    return newWorkshopsForm;
};

works like a charm! :)

from meteor-autoform.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.