I have a collection with a few arrays. I am using autoform to display various forms.
I need to pull in the existing data from the same _id into a different form field.
Here is my document with data:
{
"_id": "ERjvecg2GmSBktmn5",
"clientName": "General Motors",
"clientInfo": [
{
"fullname": "John Smith",
"email": "jsmith@gmail.com",
"phone": 2485551212,
"phone2": 7345551212
},
{
"fullname": "Billy Bob",
"email": "bbob@gmail.com",
"phone": 3135551212,
"phone2": 7346661212
}
],
"facilityList": [
{
"name": "GM @ Ann Arbor",
"id": "1234",
"facilityType": "option1",
"address": "12345 Main St Ann Arbor, MI 48888",
"contacts": [
{
"contactName": "Jill Sutton",
"contactEmail": "jsutton@gmail.com",
"contactPhone1": 7348881212,
"contactPhone2": 3132224444
}
],
"special": "gsgfsdgdsgdsgdgsdgsdgdgdgggdsgfdgdfgdgsdgsdg",
"_id": "accde038-775d-4d11-b8fd-d0cc3b63c869"
}
],
"TasksWithData": [
{
"inspectionDetails": [
{
"inspector": "cHsSP6jadYa8wAeTi",
"inspectorName": "Joe Reporter",
"projectType": "inspection",
"startDate": "2017-01-13T05:30:00.000Z",
"desc": "fgfsdgsdgsdgdsgsdgdggsdgdg",
"activeTask": false
}
],
"TaskItem": [
{
"DataFacilitySection": "dsfgsdfgds",
"DataItemDescription": "item 1",
"DataItemSection": "dfgdfgdf",
"DataItemCode": "dfgdfgdf",
"DataItemPass": null
},
{
"DataFacilitySection": "ftydftuydrtuy",
"DataItemDescription": "item 2",
"DataItemSection": "dfgdgdf",
"DataItemCode": "dfgdfgdf",
"DataItemPass": null
}
],
"author": "Ss6TjGGzqWJRZYStx"
}
]
}
Really what I need to do is get the "facilityList" objects to appear as options in a select.
I have managed to do this with data from other collections like so:
'TasksWithData.$.inspectionDetails.$.inspector': {
type: String,
label: "Inspector",
optional: true,
autoform: {
firstOption: 'Choose an Inspector',
options: function() {
return Meteor.users.find({}, {
sort: {
profile: 1,
firstName: 1
}
}).map( function ( c ){
return{
label: c.profile.firstName + " " + c.profile.lastName,
value: c._id
};
} );
}
}
},
but it seems a bit different when doing it with items from the same _id.
Here is my autoForm:
{{#autoForm collection="ClientData" id=UpdateForm type="update-pushArray" scope="TasksWithData" doc=this}}
{{> afQuickField name="inspectionDetails.0.TaskFacility"}}
{{> afQuickField name="inspectionDetails.0.inspector"}}
{{> afQuickField name="inspectionDetails.0.inspectorName"}}
{{> afQuickField name="inspectionDetails.0.projectType"}}
{{> afQuickField name="inspectionDetails.0.startDate"}}
{{> afQuickField name="inspectionDetails.0.desc"}}
<div class="panel panel-default">
{{> afArrayField name="TaskItem"}}
</div>
<input class="btn btn-primary btn-block" type="submit" value="Add Task">
{{/autoForm}}
I am a little unsure if this would get done on the autoform side or with the schema. Here is an example of the schema I am using to attempt to pull in the data:
'TasksWithData.$.inspectionDetails.$.TaskFacility': {
type: String,
label: "Choose a Facility",
optional: true,
autoform: {
firstOption: 'Choose a Facility',
options: facilityList
},
Clearly its wrong, but I would REALLY appreciate suggestions on this.