Meteor Autoform pushArray with nested schema - meteor

I'm using autoform for meteor. I have an array of nested schemas, like so:
addresses: {
type: [Schemas.address],
optional: true,
defaultValue: []
}
and I'm attempting to add an address to the array using update-pushArray
{{> quickForm id="myformid" type="update-pushArray" doc=getDocument collection=getCollection scope="addresses"}}
But I'm getting these gems:
MinimongoError: Cannot apply $push modifier to non-array
"MongoError: The field 'addresses' must be an array but is of type Object in document {_id: "383EfPJgeZQJFgs72"} [409]"
So I tried wrapping it in an array in a formToDoc hook:
SimpleSchema.clean: filtered out value that would have affected key "0", which is not allowed by the schema
So... yeah. That's the limit of my fresh ideas. What do you have?

It looks like there was an issue with the update-pushArray type until a few days after you posted this question. According to aldeed you need to be running Autoform 5.0.2 and Meteor 1.0.3.1 or higher for it to work. http://github.com/aldeed/meteor-autoform/issues/788. Also, aldeed posted a sample that might help http://autoform.meteor.com/updatepush

Related

Uncaught (in promise) FirebaseError: Invalid document reference. Document references must have an even number of segments

Well, My issue is different.. I created a modal form like this:
Modal Form
There is no issue at all and my data can be edited easily:
Updates with no errors
Now, I started to replace the text area with Vue2-editor plugin and the resulting design is like the following:
Vue-text-editor
I tried to modify the texts and save:
Error
Here is my updating mechanism:
updateProduct() {
// Update function has issues so I have to apply this work-around
this.$firestore.products.doc(this.product['.key']).set(this.product).then(() => {
this.$firestore.products.doc(this.activeItem).delete()}).then(()=>{
this.$refs.edit.hide()
toast.fire({
type: 'success',
title: 'Updated successfully'
});
});
},
Well, the firebase update function does not work at all. I have researched this, but in vain - this is the only working workaround for it.
Now I need to figure out what's wrong with that text editor.
Your problem is here:
this.$firestore.products.doc(this.product['.key'])
I don't know what the contents of this.product['.key'] is, but it's almost certainly not going to give you the name of a collection and the name of a document together. The only way you can reference a document is through a collection. Documents don't exist outside of collection. That's why the number of path segments in the string you pass to doc() must be even. It should be of the form "collection/document".
You will have to identify the collection you're writing to, and reference the path of the document using it.

Meteor dynamic form generation

I have a survey form I would like an admin to be able to add more questions to on the fly. The way I'm thinking of doing this is to have the admin add questions to a Questions collection with several properties e.g:
{
"description" : "desc",
"fieldType" : "textField",
"sortOrder" : 1,
"dataType" : "text",
"_id" : "eFopP8XFgY8Br93fA"
}
and then on the client side, loop through these using an #each block and a dynamic template like so:
{{#each questions}}
{{>Template.dynamic template=fieldType}}
{{/each}}
Now the "fieldType" field would correspond to the name of a stored template e.g
<template name="textField">
<div>
<input id="{{_id}}" type="{{dataType}}" class="validate">
<label for="{{_id}}">{{description}}</label>
</div>
</template>
and inside these templates would have different input fields depending on the type.
I have two issues:
Is this a good way to go about this problem?
If it is, how would you be able to get the values of these input fields when saving the answers (as we don't know what fields could be there at compile time)
Regarding your first question, I agree with #Kyll regarding autoform and I think you can pass the schema as a json object dynamically.
Regarding your 2nd question, please check SO question Dynamically add form fields in meteorjs where you will find answer to your second question. You can easily grab value of all fields in your dynamically created form using .serializeArray() JQuery serializeArray

Meteor 1.0 - Passing a parameter into pathFor using iron:router

I've seen a few answers on how to pass a parameter using iron:router as the third parameter, for example: href="{{pathFor 'article' _id=this._id }}"
What I would like to do is pass a parameter as the second variable (where 'article' is in the example above).
I have a collection of posts that contain a title, a body, and a type. There are three types of articles in the project I'm working on, and each type needs to be routed to a different template because the formatting is significantly different.
What I would like to be able to do is route to a particular url based on the type. An example that captures my intent but doesn't work would be this:
link
One of the "types" is "inquiry", and the route looks like this:
#route "inquiryPost",
path: "inquiry/:_id"
data: ->
Posts.findOne #params._id
waitOn: ->
[
Meteor.subscribe "posts"
]
I've tried using a helper to pass the value into the pathFor, but that didn't work either:
path: ->
type = #type
"pathFor '#{type}'"
...with this on the front end:
link
I can think of a few work arounds, but it seems to me like there should be an easier way to pass in parameters...
So, is it possible to pass in parameters into the second value of a pathFor?
Try with
<template name="example">
link
</template>
Where type is the helper
Template.example.examples({
type:function(){
return type;
}
})
Also you can try with this for example
link with many parameters
Here you where accessing for example to the route
/myRoute/type/rewr8671qew for example

Rendering MongoDB documents with Meteor

The question is: how to display complex documents returned from Mongodb.
Suppose I have two projects in my Projects collection and each project has 2 People embedded by their IDs from the People collection.
Project.find() returns this CURSOR which I'm presenting as JSON for readability:
{ "_id" : "5ed5ade8-c140-46f7-8d9e-2344fc53df8e", "name" : "Project1", "personnel" : [ "b4690c4b-d126-4737-8f40-921234567890", "977a6335-a1be-4af5-8b3f-4abcdefghijk" ] }
{ "_id" : "23f073c7-a713-4713-86a7-7d6600433146", "name" : "Project2", "personnel" : [ "b4690c4b-d126-4737-8f40-92b43072d7a1", "977a6335-a1be-4af5-8b3f-48cd5f8328db" ]}
My template in .html file:
<template name="theProjects">
{{#each theTitles}}
Name: {{name}}
Personnel: {{personnel}}
{{/each}}
</template>
renders this in the browser:
Name: Project1
Personnel: b4690c4b-d126-4737-8f40-921234567890,977a6335-a1be-4af5-8b3f-4abcdefghijk
Name: Project2
Personnel:b4690c4b-d126-4737-8f40-92b43072d7a1,977a6335-a1be-4af5-8b3f-48cd5f8328db
Questions:
The {{personnel}} field is simply being filled in by the contents of the personnel array in the Projects collect. I want to list these separately on their own line. Can't figure that out. Just slicing won't do because...
The greater need clearly is to be able to manipulate and edit the Personnel data so the template has to be properly Meteor reactive.
Now the hard one: the personnel ID's from the People collection are embedded in the Project documents. How would I use Meteor to replace the ID's with the appropriate names from the Personnel collection and still keep their data reactivity?
I know this is a lot to ask but these kind of things seem like they are foundational to bigger and more complex web site.
Thanks everyone.
https://gist.github.com/3220991
This is a gist I made to show you use the of Handlebars helpers. This will stay reactive and is very easy to use. I hope you can use it.
If you need more help or comments , just mention me.

filter functions problem

I'm working on a search component for an app I'm working on and I needed to add some filters to it. I've found an example and got the first filter working fine.
Now I'm trying to add a second filter I'm running into problems... In the example I found they use filterFunctions, but I only get an option for filterFunction, why is that?
Here's the example code
productsCollection.filterFunctions =
[
filterByPrice, filterByType,
filterByCondition, filterByVendor
]
And this is what I'm trying
acData.filterFunction = [filterByStatus, filterByDate]
but with this code I get the following error message - 1067: Implicit coercion of a value of type Array to an unrelated type Function.
Why am I getting this error and how would I go about add multiple filters to my Array Collection?
Thanks!
filterFunction must be set to a single function, not an Array or any other datatype. To combine multiple functions create one that combines them, like this:
acData.filterFunction = function(item:Object)
{
return
filterByPrice(item) &&
filterByType(item) &&
filterByCondition(item) &&
filterByVendor(item);
};
If you saw a sample that used filterFunctions plural that accepted an array, post a link. That's not anywhere in the standard Flex framework or in the new 4.0 beta afaik.
It looks like you are going to have to extend an arraycollection to make it work. this link should spell it out for you: http://blog.rotundu.eu/flex/arraycollection-with-multiple-filter-functions/

Resources