Updating array field in collection
I am wondering how I can make a field variable in collection into an array. I havent seen documentation or an example on how to.
"name": "rosters", "fields": [ { "name": "position", "title": "Position", "type": "array", "lookup_query_name": "stars", "input": "select", "lookup_field": "name", "lookup_key": "_id", "join_collection": "stars", "join_fields": ["name"], "join_container": "astar" }, { "name": "depth", "title": "Depth", "type": "integer", "min": 2 }
This creates the array of field position but I am unable to populate the field beyond the first array position in any update/insert form. I would like to set the size of the array to depth variable if possible. Help is greatly appreciated!
I used this in the collection to add in empty data. The edit form from still doesnt show the position as multiple values just the first position in the array.
' "after_insert_code":" for(var i = 1; i <doc.roster_depth; i++) { Rosters.update({ props_reference : doc._id}, { $push: {position: 'empty'}}); }"
@maco144 you will get answer few hours after now.
@maco144 Sorry, I don't fully understand:
-
What input control you want in the form? Checkbox or multi-select, or "tag" input or... ?
-
What is "depth" - is it number of items in the array, and if user don't choose "depth" number of items, remaining items should be populated with string "empty"?

This is what I get displaying the following component. I want there to show the full positions array and be able to update through a 'select'.
"components": [ { "name": "view_private_weekly", "type": "form", "mode": "update", "title": "Weekly Roster", "page_size": 10, "text_if_empty": "No stars :(", "query_name": "current_weekly_roster", "query_params": [], "submit_button_title": "SUBMIT ROSTER", "submit_route": "weekly_private", "edit_route": "weekly_private.edit", "edit_route_params": [ { "name": "rosterId", "value": "this._id" } ], "details_route": "weekly_private.details", "details_route_params": [ { "name": "rosterId", "value": "this._id" } ] } ]
Depth is used to set the position array to size and then it is populated with 'empty'.
@maco144 sorry, but I still don't understand what you wish to have in the form: do you want multiple "select" inputs (one for each item in the array) or... ?
@maco144 sorry, but I still don't understand what you wish to have in the form: do you want multiple "select" inputs (one for each item in the array) or... ?
@perak Yes that's exactly it. How do I get a form to display each array and allow it to be selected? Thank you.
@perak Do you have any suggestions? I have tried using a few different methods such as events_code, helpers_code, template_rendered_code, and more without success.