Reputation: 142
The html is as follows:
<template name="addUser">
{{#autoForm id="addUser" schema=schema meteormethod="newUser"}}
<fieldset>
{{> afQuickField name="fName"}}
{{> afQuickField name="lName"}}
{{> afQuickField name="username"}}
{{> afQuickField name="email"}}
{{> afFormGroup name="roles" firstoption="Select Role" options=addUseroptions type="select"}}
{{> afQuickField name="password"}}
<div>
<button type="submit" class="btn btn-primary">Submit</button>
<button type="reset" class="btn btn-default">Reset</button>
</div>
</fieldset>
{{/autoForm}}
</template>
The afFormGroup roles is not populating. I am attempting to populate a dropdown box with all of the roles currently stored in the mongodb, but the dropdown remains empty. The correct values are shown in the console from the console.log() statements.
The js is as follows:
Template.addUser.helpers({
schema : function (){
return MySchema.addUser;
},
collection : function (){
return MyCollections.Users;
},
addUseroptions: function (){
var array = [];
var array2 = [];
roles = Roles.getAllRoles();
array = roles.fetch();
for(var i = 0; i < roles.count(); i++){
array2[i] = array[i].name;
}
console.log(roles.count());
console.log(array2);
return
[{
optgroup: "Roles",
options: array2
}];
}
});
Upvotes: 0
Views: 159
Reputation: 1432
Your help function seems a bit confused. Try this:
// Still inside your "helper" block
addUseroptions: function() {
return Roles.getAllRoles().map(function(r) {
// "r" here is a single document returned by the cursor. Use this
// space to do whatever change you wanna do in respect to
// label name or select value
return {label: r.name, value: r.name};
});
}
Upvotes: 1