Meteor Auto Form Access Attached Property
I have some related schematics and am trying to access subcircuit properties from the form for the primary schema. I know it. The code might help:
//js
Collection = new Meteor.Collection('collection');
Schemas = {};
Schemas.secondary = new SimpleSchema({
unitType: {
type: String,
autoform: {
type: 'select',
options: //function with all the options
}
}
});
Schemas.primary= new SimpleSchema({
name: {
type: String,
},
units: {
type: [ Schemas.secondary ]
}
});
Collection.attachSchema(Schemas.primary);
//HTML
{{#autoForm collection="Collection" id="someId" type="insert"}}
{{> afQuickField name='name'}} // this works
{{> afQuickField name='units'}} // this works
{{> afQuickField name='units.unitType'}} // this doesn't work :-(
{{/autoForm}}
The reason I am doing this is because there are other properties in the secondary schema that I want to show conditionally based on the value of the select box. I also tried putting the form inside the form and then running {{#each afFieldNames name='"units"}}
, but that didn't quite work either. Instead of giving me only the fields that are in units (i.e. Secondary schema), it iterates over all fields, both primary and secondary.
Thoughts? I am not married to this scheme, but I cannot think of anything else.
Thanks again. dB
source to share
I had this problem.
Give this move
{{> afQuickField scope='units.unitType' name='units.unitType'}}
If you reset your modifier in your proposal, you should be able to see the subdocument filled in
AutoForm.hooks({
someId: {
before: {
'insert': function(modifier) {
console.log(modifier);
}
}
}
});
Let me know if this works for you!
All the best, Elliot
source to share