Comments (7)
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.
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.
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.
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 returnsmyCollection2.callbacks is deprecated; use myCollection2.hooks
weird
Reply to this email directly or view it on GitHub:
#50 (comment)
from meteor-autoform.
@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.
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.
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)
- afQuickField id field is overwritten - v7 HOT 9
- Array of objects set last object fields to null when remove unordered element HOT 6
- Cleanup issues, that are fixed by v7
- Problem with Meteor 1.11.1 Blazejs HOT 5
- Create a native 'autocomplete' type for `afQuickfield` in `AutoForm` that is Bootstrap themed. HOT 1
- Outdated links to SimpleSchema in README
- select-radio and select-radio-inline not working for update HOT 10
- minCount and maxCount undefined inside afEachArrayItem HOT 5
- quickForm and autoForm not displaying - no error messages. HOT 8
- Make moment a weak dependency
- Run a meteor method in before hook and await callback? HOT 4
- Autoform hooks onSuccess not working HOT 13
- Demo link stale HOT 2
- Option list unwanted memory autosave form HOT 4
- Validation messages not showing - SimpleSchema 3.x HOT 4
- Why is there throttling on validateField HOT 2
- Remove global variables HOT 1
- Add coverage report to tests HOT 1
- Please add error/warning messages if no theme is installed HOT 4
- Cross - Posting: Incompatibility with Blaze-Async-PR HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from meteor-autoform.