// Takes a input form element and a hidden form element (to store the selected id in) along with an array of objects, to build a dropdown select control that allows the user to type part of the selection to filter the list.
//Ensure that if the hidden field exists and changes, that the hidden field's id matches the text in the input field. If not then the hidden id field was changed manually and externally and the text field should be updated.
//Setup the list to highlight the item the user is hovering over, to select the item the user clicks, and to remove the hover styling when the list closes due to a selection being made.
//Handle key events on the input field. Up/down arrows should change the selection in the list. Enter should select an item and close the list. Tab and escape should hide the list before moving to the next focusable element on the Admin.
//Filter the set of elements so that only those matching the text in the input field are marked as visible.
_this.filter();
}
Tracker.autorun(function(){
this.$list.empty();
if(options.cursor){
//Add the initial set of data.
add(options.cursor.fetch());
}
elseif(options.set){
for(leti=0;i<options.set.length;i++){
add(options.set[i]);
}
}
}.bind(this));
//Check the hidden input field for an ID, and setup the selection based in it if there is one.
if(this.$hidden&&_this.$hidden.val()){
hiddenInputChanged();
}
//TODO: Should probably check to ensure comparator is a function? Not that it will help much if the function is not written correctly. Stupid Javascript!
cursor:undefined,//A meteor Cursor used to populate the values displayed in the combo.
set:[],//An array of values displayed in the combo. This must be specified if cursor is not specified.
selection:undefined,//A meteor ReactiveVar whose value will be set to the current selection.
comparator:function(a,b){returna===b;},//A function that takes two collection objects and compares them for equality. If the combo shows users for example, this comparator would compare one user id to another. Required for the combo to set the selection if the view changes it externally relative to this combo.
textAttr:undefined,//The attribute of the data elements to use for the name. This can also be a function that takes the data object and returns the text.
idAttr:'id',//The attribute of the data elements to use for the ID. This can also be a function that takes the data obejct and returns the ID.
// groupFunctions: The object containing three functions: 'groupParent', 'parentText', 'children'.
// groupParents(data) will take a data element and return the objects that best represents the parents of the children (for a multi layer tree, this would be the node just before the leaf nodes).
// parentText(parent) will be passed the group parent and the data object that generated it, and will return the text that represents the path to that parent.
// children(parent) will be passed the group parent (returned by groupParents()), and will return an array of children or leaf nodes for the tree.
groupFunctions:undefined,
filter:true,//Whether to filter the list as the user types.
effects:'fade',
duration:'200',
listClass:'de.combo-list',
selectionClass:'selected',//The class to use for the selected element in the dropdown list.
getClasses:undefined//An optional function that will return a string to use in the list item's class attribute to style the list item for a given model data. The function will be passed the data object for the list item.
//Note: Don't trigger the select event - for some reason it causes the dropdown to reopen and the control to retain focus when clicking out of the widget.
// Removes all filtering. This is used to clear the filtering when first opening the combo when there is a value in the field. This is desirable because when we have an exact match, but are opening the combo, we most often want to select a new value.
// show all list items that are not nodes and whose text matches the input value;
// show all node list items associated with visible child list items (they occur after the parent, so the parent will be hidden first, then made visible).
// Position the list relative to the field. Note that we place the combo at the top of the Admin (in the body tag) to avoid overflow not showing and to ensure the Admin scrolls if needed.
// goDown: true/false - defaults to true - indicating whether the highlighting should go up or down if the requested item is a node. Nodes cannot be highlighted or selected.