I would to get options data from Mongo Meteor to Select Options
<SelectField
name="parent"
options={MongoData}
/>
Please help me.
Hi @thearabbit
You can use a dynamic schema or the options as you stated there:
let data = [{label: 'hey', value: 'asdasd'}]
<SelectField options={data}/>
if you are using a schema, try doing this:
let mySchema = new SimpleSchema({
items: {
type: 'String',
uniforms: {
options: getOptionsFromDb() // Returns an array of label/value
}
}
And set the schema in the form <AutoForm schema={mySchema} />
Thanks for your reply.
But I not clear how to get data from mongo put to Schema.
I base on Meteor and use createContainer.
Could example for fullly?
Hey @thearabbit, please read createContainer docs first, then share your work related to this issue which actually is irrelevant to responsibilities of this package.
Closing this, but if you want to share your code related with this issue please feel free to do it here.
Hi @thearabbit I use meteor too.
Just fetch the data and pass it to the new schema, or the field.
Fetching data from mongo:
myCollection.find().fetch().map(function(item){
return { label: item.name, value: item._id}
})
Passing it to a react element (one of multiple ways)
<myReactElement options: { this.getData()} />
I am having problems using uniforms fields
I have:
const Address = new SimpleSchema({
path: {
type: String,
label: "Direccion"
},
cp: {
type: String,
label: "Codigo postal"
},
location: {
type: String,
label: "Localidad",
uniforms: {
options: function() {
return Locations.find().map((l,i)=>{
return { label: l.name, value: l._id };
});
}
}
}
});
this gives me:
Error: Invalid definition for location field: "uniforms" is not a supported property
I am using Meteor with npm: "uniforms": "^1.17.2" and "uniforms-unstyled": "^1.17.2"
Most helpful comment
@lmaddio _Note: remember to import uniforms packages first._