ComboBox Class

Form input with a pulldown list of options. By default, the options are accessed via a button or a "down arrow" key press. The list of options are automatically filtered as a user types in a value in the input field.

Constructors

ComboBox( parent, config )
Used to instantiate this class
parentDOM element in which to render this component
configConfiguration settings (optional). See config options for more information.

Config Options

placeholder
Placeholder text to display in the input. No placeholder text is set by default.
spellcheck
If true, the browser will spellcheck text in the input field. Default is false.
maxVisibleRows
The number of menu items to that appear in the dropdown menu before overflow. Default is 5.
scrollbar
If true, will display a vertical scrollbar in the dropdown menu. Default is true.
showMenuOnFocus
If true, will display the dropdown menu whenever the input has focus (e.g. on mouse click). Default is true.
typeAhead
If true, the list of options in the dropdown menu are automatically filtered as a user types in a value in the input field. Default is true.
readOnly
If true, will prevent user from typing or copy/pasting values in the input field. Default is false.
options
A static list of options to put in the dropdown menu. Example:
        [
            {
                label: "Previous Year",
                value: "prevYear"
            },
            {
                label: "Current Year",
                value: "currYear"
            },
            {
                label: "Next Year",
                value: "nextYear"
            }
        ]
        
Use the add() method to add items dynamically.
addNewOption
If true, will display a static menu item at the bottom of the drop down menu. This extra menu option is commonly used to render a popup menu/dialog. The onAddNewOption() method can be overridden to handle when this item is selected. The addNewOptionText config option is used to set the text/label for this menu option. Default is false.
addNewOptionText
Text to display in the extra menu option when addNewOption is set to true. Default is "Add New..."
style
Style for individual elements within the component. Note that you can provide CSS class names instead of individual style definitions.

Events

onChange( label, value, prevLabel, prevValue )
Called when the input value changes
onAddNewOption( )
Called when a user clicks on the "new" menu option that appears at the bottom of the dropdown menu. See addNewOption config option.
onMenuShow( )
Called when the menu is made visible
onMenuHide( )
Called when the menu is hidden
onMenuContext( label, value, el )
Called when a user attempts to render the context menu on a menu option
onMenuHover( label, value, el )
Called when a user hovers over an item in the dropdown menu

Public Methods

isDisabled( )
Returns true if the compnentent has been disabled.
enable( )
Used to enable the input allowing users to interact with the component.
disable( )
Used to disable the input preventing users from interacting with the component.
reset( )
Similar to the clear() method, this will clears the input value. However, unlike the clear() method, this method will retain all the items in the dropdown menu.
setValue( value, silent )
Used to set the value for the input.
valueA label or value found in the dropdown menu. This parameter is required.
silentBy default, if the input value is changed, it will fire. the onChange event. When silent is set to true, the input will NOT fire the onChange event. This parameter is optional.
getValue( )
Returns the selected value associated with the input.
getText( )
Returns the text displayed in the input.
getOptions( )
Returns an array of all the menu options currently available in the dropdown menu. Elements in the array will include a "text", "value", and "el" for each entry. Example:
    [
      {
        text: "United States",
        value: "US",
        el: div
      },
      {
        text: "Mexico",
        value: "MX",
        el: div
      },
      ...
    ]
    
getInput( )
Returns the DOM element for the input.
getButton( )
Returns the DOM element for the button.
filter( )
Used to filter items in the dropdown menu that start with the text in the input.
clear( )
Clears the input and removes all items from the dropdown menu.
showMenu( removeFilter )
Renders the dropdown menu if it is hidden.
removeFilterIf true, expand the list and view all the options.
hideMenu( )
Hides the dropdown menu if it is visible.
add( label, value )
Used to add an entry to the dropdown menu. Returns the new menu item as a DOM element with custom methods like setLabel()
labelText or element to display in the dropdown menu. The label will appear in the input when menu item is selected. This parameter is required.
valueValue associated with the input. This parameter is optional. If undefined, the label will be used as the value.
remove( value )
Removes an entry from the menu.
removeAll( )
Removes all entries from the menu.