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

TypeError: templateInstance.collection.findOne is not a function. -- With Meteor, fairly basic implementation using <divs> with form elements inside #768

Closed
screaser opened this issue Feb 2, 2016 · 7 comments

Comments

@screaser
Copy link

screaser commented Feb 2, 2016

Using Meteor I implemented a pretty basic rubaxa:sortable instance. Not using multiple sortable lists or anything fancy. Pre-loaded "order" data in my Mongo Collection with unique numbers 1, 2, 3, etc.

Everything displays fine, and lets you sort once then the package dies when it tries to save the new order to the DB.

Error in the browser console is:
TypeError: templateInstance.collection.findOne is not a function. (In 'templateInstance.collection.findOne(itemId)', 'templateInstance.collection.findOne' is undefined) adjustOrdersrubaxa_sortable.js:1404 sortableUpdaterubaxa_sortable.js:1446 _dispatchEventrubaxa_sortable.js:1102 _onDroprubaxa_sortable.js:799 (anonymous function) handleEventrubaxa_sortable.js:853

Relevant code snippets below...

Server:
Products = new Mongo.Collection('products'); Sortable.collections = ['products'];

Client:
<div class="sortable target" id="object"> {{#sortable items=products animation="100" handle=".sortable-handle" ghostClass="sortable-ghost" sortField="order"}} {{> productSettingsRow}} {{/sortable}} </div>

`

...
...
`

Tried searching the Issues; don't see anything quite like this though #578 seems similar(?). Also didn't see a way to recreate in the JS scratchpad as requested since it has to do with DB access...

Any suggestions, or any other info I can provide to help debug?

@granda
Copy link

granda commented Feb 3, 2016

Looks to be that Sortable for Meteor doesn't support Array's yet. 😔

https://github.com/RubaXa/Sortable/blob/6140e497fb74a43b91383cef65886500dfec29ea/meteor/reactivize.js#L57

@screaser
Copy link
Author

screaser commented Feb 3, 2016

Ah -- yes. The helper that was feeding in "products" was:

Template.productSettings.helpers({
products : function() {
return Mongo.Products.find().fetch();
}
});

I've changed that to:

Template.productSettings.helpers({
products : function() {
return Mongo.Products.find();
}
});

... and now this particular error isn't happening. Now it just says "Access Denied" when the update tries to occur. Progress?!?

@screaser
Copy link
Author

screaser commented Feb 4, 2016

In case this helps anyone else... it looks like this plugin doesn't quite work out-of-the-box with Meteor when you are not in insecure mode. To fix, you need to manually allow update access to the collection like this (in my case the collection is Products):

Products.allow({
update: function updateProducts(userId, doc, fieldNames, modifier) {
if (fieldNames.length !== 1 || fieldNames[0] !== 'order') return false;
if (!Match.test(modifier, {$set: {order: Number}})) return false;
if (Meteor.users.findOne(userId, {fields:{Id:1}}).Id !== doc.Id) return false;
return true;
}
});

@RubaXa
Copy link
Collaborator

RubaXa commented Feb 5, 2016

Dear all! Meteor is moved to the separate repository. If this issue is still actual, please create it there once again.

For your info: this project needs a maintainer.

@RubaXa RubaXa closed this as completed Feb 5, 2016
@RubaXa RubaXa added the meteor label Feb 5, 2016
@screaser
Copy link
Author

screaser commented Feb 5, 2016

Good to know! The page on Atmosphere.js still points to the non-Meteor GitHub page... is there any way to get that updated?

https://atmospherejs.com/rubaxa/sortable >> https://github.com/RubaXa/Sortable/

@jowilhnson
Copy link

Thanks screaser, you are a life saver!
Too bad this package still doesn't really work for meteor. Fixing one error just leads to another.
And yes, the atmoshpere page still points to this GitHub page.

@jdmswong
Copy link

jdmswong commented Apr 4, 2016

had this problem too, the atmosphere link still points here please correct it!
https://atmospherejs.com/rubaxa/sortable

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

5 participants