Skip to content

Fetch data from Collection fields #72

Description

@danyhiol

First thanks @aldeed for this powerful package.
I'll like to use this package along with autoForm, simple_schema and collection2 to pull data from collection fields and display them as select-option for a specific array-field.
here is my code:

Schemas.Info = new SimpleSchema({
    field1: {
        type: SimpleSchema.Integer,
        label: "Field One",
        optional: true
    },
    mailingAddress: Object,
    'mailingAddress.street': String,
    'mailingAddress.city': String,
    field2: {
        type: String,
        label: "Field Two",
        optional: true
    }
});
Schemas.Member = new SimpleSchema({
member: {
        type: Array,
        optional: true,
        label: 'Chose a member',
        autoform: {
            type: 'select2',
            afFieldInput: {
                multiple: true
            },
            options: function() {
                return Books.find({}, { fields: { 'Info.mailingAddress': 1 } }).map(function(c) {
                    return {
                        label: c.name,
                        value: c._id
                    };
                });
            },
            selectOnBlur: true, 
            placeholder: 'Select a member' // this option is not working
        }
    },
    'member.$': String
});

Schemas.Items.extend(Schemas.Member);

Schemas.Items.extend(Schemas.Info);

The select field is beeing displayed as a dropdown. I've performed 4 inserts in the Info Schema. I'll like to pull those data from the collection (using this code:

options: function() {
                return Books.find({}, { fields: { 'Info.mailingAddress': 1 } }).map(function(c) {
                    return {
                        label: c.name,
                        value: c._id
                    };
                });
            },

)

But it is not working. I want to avoid using helpers so I can have all my database logic at one place using schema. Any help will be grateful.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions