I am having trouble getting the value of a field from a nested schema.
Recipes.attachSchema(new SimpleSchema({
recipeIngredients: {
type: [Object],
optional: true,
blackbox: true
},
"recipeIngredients.$.ingredient": {
type: String,
label: "Ingredient",
optional: true,
autoform: {
options: function() {
var currentUserId = Meteor.userId();
return Ingredients.find({createdBy: currentUserId}).map(function (doc) {
return {label: doc.ingredientName, value: doc._id};
})
}
}
},
"recipeIngredients.$.amount": {
type: String,
label: "Amount",
optional: true
},
"recipeIngredients.$.metric": {
type: String,
label: "Metric",
optional: true
},
"recipeIngredients.$.condition": {
type: String,
label: "Condition",
optional: true
},
"recipeIngredients.$.cost": {
type: Number,
label: "Cost",
optional: true,
decimal: true,
autoform: {
afFieldInput: {
type: "hidden"
},
afFormGroup: {
label: false
}
},
autoValue:function(){
console.log(this.field('recipeIngredients.ingredient').value);
console.log(this.siblingField('recipeIngredients.ingredient').value);
console.log(this.field('recipeIngredients.$.ingredient').value);
console.log(this.field('recipeIngredients.0.ingredient').value);
console.log(this.field('ingredient').value);
console.log(this.siblingField('recipeIngredients.$.ingredient').value);
console.log(this.siblingField('recipeIngredients.0.ingredient').value);
console.log(this.siblingField('ingredient').value);
}
},
All of the console logs above return undefined.
If I use…
console.log(this.field('recipeIngredients'));
I get…
Object {isSet: true, value: Array[1], operator: "$set"} isSet: true operator: "$set" value: Array[1] 0: Object amount: "400" ingredient: "vLmoGvbrW2zLoxWXs" <-- THIS IS THE VALUE I NEED metric: "grams" __proto__: Object length: 1 __proto__: Array[0] __proto__: Object
How can I get the value of the “ingredient”?
Thanks