简体   繁体   中英

Meteor Add Users to Form Select

I am a little surprised I am not finding anything out there on this. My question is really 2 parts:

  1. Is it possible to generate a form select field (preferably with Autoform) with all of the options being registered users emails or names? If so could anyone please provide an example?
  2. Is it possible (again autoform is preferred) to have conditional form field rules. EX: I have a client with multiple locations. One select would be for the client, and depending on what is selected here would populate another select that generates all of this clients locations. Again ANY examples would be appreciated!

Thanks so much!

Autoform is awesome work done by aldeed. So much of functionality inside it, it would take some time to read and understand the documentation. I will try to help with an example.

  1. Is it possible to generate a form select field (preferably with Autoform) with all of the options being registered users emails or names? If so could anyone please provide an example?
var myAutoForm = new SimpleSchema({

    "formSelectField": {
        type: String,
        autoform: {
            type: "selectize",
            options: function() {
                return collectionName.find({ criteria to get  the registered user names }).map(function(c) {

                    var optionsArray = [];
                    for (var i = 0; i < c.length; i++) {
                        optionsArray[i] = {}; // creates a new object
                        optionsArray[i].label = c[name][i];
                        optionsArray[i].value = c[name][i];
                    }
                    return optionsArray;
                })[0];
            },
            defaultValue: function() {
                return the default value to be picked on the select dropdown

            },

        }
    },
});
  1. Is it possible (again autoform is preferred) to have conditional form field rules. EX: I have a client with multiple locations. One select would be for the client, and depending on what is selected here would populate another select that generates all of this clients locations. Again ANY examples would be appreciated!

For this, I will put only the options part of the autoform

options: function() {
        if(AutoForm.getFieldValue('fieldName', 'formId')==='something')
        })
            return someValue;
    },

Really not answering but rather just giving a better visual of the code I added. I am getting an input box but not a select box. There is nothing inside the input. Here is what I added:

 inspector: { type: String, autoform: { type: "selectize", options: function() { return Meteor.users.find({}, fields: { emails: 1, profile: 1 }).map(function(c) { var optionsArray = []; for (var i = 0; i < c.length; i++) { optionsArray[i] = {}; optionsArray[i].label = c[name][i]; optionsArray[i].value = c[name][i]; } return optionsArray; })[0]; }, defaultValue: function() { return "Choose a User"; }, } }, 

Just curious what I got wrong.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM