Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid .map to fill options #38

Open
luixal opened this issue Mar 22, 2018 · 0 comments
Open

Avoid .map to fill options #38

luixal opened this issue Mar 22, 2018 · 0 comments

Comments

@luixal
Copy link

luixal commented Mar 22, 2018

Hi,

Not sure if this project is still active... would be good to know :)

I'm having an issue with selectizeOptions, if I define a field this way:

rolesSchema = new SimpleSchema({
  projectId: {
    type: String,
    label: 'project',
    optional: true,
    autoform: {
      // type: "universe-select",
      type: "selectize",
      options: function () {
        return Projects.find().map(function (project, index, cursor) {
          return {
            label: project.name,
            value: project._id
          };
        });
      }
    }
  },

It works like a charm (slow, due to mapping I guess...). If I define it this way (to avoid mapping the entire collection):

projectId: {
    type: String,
    label: function () {
      return I18N.translate('project');
    },
    optional: true,
    autoform: {
      // type: "universe-select",
      type: "selectize",
      options: function () {
        return Projects.find().fetch();
      },
      selectizeOptions: {
        labelField: 'name',
        valueField: '_id'
      }
    }
  },

It doesn't work showing this kind of error on clients console (just one line here, it shows one line per item in the Projects collection):

duplicate id undefined in [...]
{name: "detailedRoles.0.projectId", label: undefined, value: undefined, _id: undefined, selected: false}

It seems it's not taking selectizeOptions in count. Any idea on how to make this work avoiding the .map?

Thanks!

PS: I can't make the mapping in the server and publishing it, I need _id and name values to stay put for showing, editing and other operations.
PS2: yep, I could replicate _id and name in value and label but it seems too much hardcore to me...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant