# Input 101

This page shows how to get started with Wijmo's Input controls.

## Getting Started

Steps for getting started with Input controls in JavaScript applications:

1. Add references to Wijmo.
2. Add markup to serve as the Wijmo control's host.
3. Initialize the Wijmo control(s) via JavaScript.
4. (Optional) Add some CSS to customize the input control's appearance.

HTML
<input id="gsInputNumber">
JS
var inputNumber = new wijmo.input.InputNumber('#gsInputNumber', { value: 3.5, step: 0.5, format: 'n2' });

#### Result (live):

## AutoComplete

The AutoComplete control is an auto-complete control that allows you to filter its item list as you type, as well as select a value directly from its drop-down list.

To use the AutoComplete control, you must minimally set the itemsSource property to an array of data in order to populate its item list. The AutoComplete control also offers several other properties to alter its behavior, such as the cssMatch property. The cssMatch property allows you to specify the CSS class that is used to highlight parts of the content that match your search terms.

The example below uses an array of strings to populate the AutoComplete control's item list using the itemsSource property. To see a list of suggestions, type "ab" or "za" in the AutoComplete controls below.

HTML
<div class="app-input-group"> <label for="acAutoComplete1">itemsSource Only</label> <div id="acAutoComplete1"></div> </div> <div class="app-input-group"> <label for="acAutoComplete2">itemsSource & cssMatch</label> <div id="acAutoComplete2"></div> </div>
JS
var autoComplete1 = new wijmo.input.AutoComplete('#acAutoComplete1', { itemsSource: data.countries }); var autoComplete2 = new wijmo.input.AutoComplete('#acAutoComplete2', { itemsSource: data.countries, cssMatch: 'highlight' // CSS class for custom highlighting });
CSS
.highlight { /* custom AutoComplete highlight */ background-color: #ff0; color: #000; }

#### Result (live):

itemsSource Only
itemsSource & cssMatch

## ComboBox

The ComboBox control is very similar to the AutoComplete control, but rather than providing a list of suggestions as you type, the ComboBox will automatically complete and select the entry as you type.

Like the AutoComplete control, you must minimally set the ComboBox's itemsSource property to an array of data in order to populate its item list. You may also want to specify whether the ComboBox is editable via the isEditable property. The isEditable property determines whether or not a user can enter values that do not appear in the ComboBox's item list.

The example below uses two ComboBoxes bound to the same data source as the AutoComplete control above. The first ComboBox's isEditable property is set to false, while the second ComboBox's isEditable property is set to true.

HTML
<div class="app-input-group"> <label>Non-Editable</label> <div id="cbComboBox1"></div> </div> <div class="app-input-group"> <label>Editable</label> <div id="cbComboBox2"></div> </div>
JS
var comboBox1 = new wijmo.input.ComboBox('#cbComboBox1', { isEditable: false, itemsSource: data.countries }); var comboBox2 = new wijmo.input.ComboBox('#cbComboBox2', { isEditable: true, itemsSource: data.countries });

#### Result (live):

Non-Editable
Editable

## InputDate & Calendar

The InputDate control allows you to edit and select dates via a drop-down calendar, preventing you from entering an incorrect value. The InputDate's drop-down calendar was developed as a separate control and can be used be used independently from the InputDate control.

Both InputDate and Calendar, specify several properties to alter the controls' behavior. The most commonly used properties include:

- value: Specifies the date value for the control.
- min: Specifies the minimum date value that can be entered in the control.
- max: Specifies the maximum date value that can be entered in the control.

The example below demonstrates how to use each of these properties.

HTML
<div class="app-input-group"> <label>Bound InputDate with min & max</label> <input id="idcInputDate" type="text" /> </div> <div class="app-input-group"> <label>Bound Calendar with min & max</label> <input id="idcCalendar" type="text" style="width:300px;" /> </div> <p> <b> Valid Range: <span id="idcMinDate"></span> to <span id="idcMaxDate"></span> </b> </p>
JS
var today = new Date(), minDate = new Date(today.getFullYear(), 0, 1), maxDate = new Date(today.getFullYear(), 11, 31); var inputDate = new wijmo.input.InputDate('#idcInputDate', { value: today, min: minDate, max: maxDate }); var calendar = new wijmo.input.Calendar('#idcCalendar', { value: today, min: minDate, max: maxDate }); // show date range values below the example var format = 'MMM d, yyyy'; document.getElementById('idcMinDate').textContent = wijmo.Globalize.format(minDate, format); document.getElementById('idcMaxDate').textContent = wijmo.Globalize.format(maxDate, format);

#### Result (live):

Bound InputDate with min & max
Bound Calendar with min & max

Valid Range: to

## InputDate & InputTime

Similar to the InputDate control, the InputTime control allows you to modify the time portion of a JavaScript date. The InputTime control shares many of the same properties as the InputDate control, including format, min, max, and value. The InputTime control also offers a step property that allows you to specify the number of minutes between entries in its drop-down list.

The example below illustrates how to use the InputTime control in conjunction with the InputDate control. Notice that these controls work together to edit the same DateTime JavaScript Object and only update the part of the DateTime that they are responsible for.

HTML
<div class="app-input-group"> <label>Bound InputDate with min, max, & format</label> <input id="iditInputDate" type="text" /> </div> <div class="app-input-group"> <label>Bound InputTime with min, max, & step</label> <input id="iditInputTime" type="text" /> </div> <p> <b>Selected Date & Time: <span id="iditSelectedValue"></span></b> </p>
JS
var inputDate = new wijmo.input.InputDate('#iditInputDate', { valueChanged: valueChanged, min: new Date(today.getFullYear(), 0, 1), max: new Date(today.getFullYear(), 11, 31), format: 'MMM dd, yyyy' }); var inputTime = new wijmo.input.InputTime('#iditInputTime', { valueChanged: valueChanged, min: new Date(0, 0, 0, 7, 0, 0, 0), max: new Date(0, 0, 0, 19, 0, 0, 0), step: 15 }); valueChanged(); // valueChanged event handler function valueChanged() { if (inputDate && inputTime) { // merge date and time values var val = wijmo.DateTime.fromDateTime(inputDate.value, inputTime.value); // format and display the new date var dateTime = wijmo.Globalize.format(val, 'MMM dd, yyyy h:mm:ss tt'); document.getElementById('iditSelectedValue').textContent = dateTime; } }

#### Result (live):

Bound InputDate with min, max, & format
Bound InputTime with min, max, & step

Selected Date & Time:

## ListBox

The ListBox control displays a list of items and allows you to select items using your mouse and keyboard. Like the AutoComplete and ComboBox controls, you must specify the ListBox's itemsSource property in order to use the control.

The example below allows you to select an item within the ListBox control, and also displays the control's selectedIndex and selectedValue properties.

HTML
<div class="app-input-group"> <div id="lbListBox" style="height:150px;width:250px;"></div> </div> <p> <b>selectedIndex: <span id="lbSelIdx"></span></b> </p> <p> <b>selectedValue: <span id="lbSelVal"></span></b> </p>
JS
var listBox = new wijmo.input.ListBox('#lbListBox', { selectedIndexChanged: function (s, e) { document.getElementById('lbSelIdx').textContent = s.selectedIndex; document.getElementById('lbSelVal').textContent = s.selectedValue; }, itemsSource: data.cities });

#### Result (live):

selectedIndex:

selectedValue:

## InputNumber

The InputNumber control allows you to edit numbers, preventing you from entering invalid data and optionally formatting the numeric value as it is edited. The InputNumber can be used without specifying any of its properties; however, you'll typically want to bind it to some data using the value property.

In addition to the value property, the InputNumber control offers several other properties that can be used to alter its behavior, such as:

- min: Specifies the minimum numeric value that can be entered.
- max: Specifies the maximum numeric value that can be entered.
- step: Specifies the amount to add or subtract from the current value when the spinner buttons are clicked.
- format: Specifies the numeric format used to display the number being edited. The format property uses a .NET-style numeric format string.

The example below demonstrates how to use all of these properties.

HTML
<div class="app-input-group"> <label>Unbound with "n0" format</label> <input id="inInputNumber1" type="text" /> </div> <div class="app-input-group"> <label>Bound with "n" format</label> <input id="inInputNumber2" type="text" /> </div> <div class="app-input-group"> <label>Bound with min (0), max (10), step, and "c2" format</label> <input id="inInputNumber3" type="text" /> </div> <div class="app-input-group"> <label>Unbound with placeholder and isRequired="false"</label> <input id="inInputNumber4" type="text" /> </div>
JS
var inputNumber1 = new wijmo.input.InputNumber('#inInputNumber1', { value: 0, format: 'n0' }); var inputNumber2 = new wijmo.input.InputNumber('#inInputNumber2', { value: Math.PI, format: 'n' }); var inputNumber3 = new wijmo.input.InputNumber('#inInputNumber3', { value: 3.5, format: 'c2', step: 0.5, min: 0, max: 10 }); var inputNumber4 = new wijmo.input.InputNumber('#inInputNumber4', { placeholder: 'Enter a number...', isRequired: false, value: null });

#### Result (live):

Unbound with "n0" format
Bound with "n" format
Bound with min (0), max (10), step, and "c2" format
Unbound with placeholder and isRequired="false"

## InputMask

The InputMask control allows you to validate and format user input as it is entered, preventing invalid data. The InputMask control can be used without specifying any of its properties; however, you will typically set its value and mask properties. Like the other Wijmo input controls, the value property specifies the value for the InputMask control. The mask property specifies the control's mask and supports a combination of the following characters:

0
  Digit.
9
  Digit or space.
#
  Digit, sign, or space.
L
  Letter.
l
  Letter or space.
A
  Alphanumeric.
a
  Alphanumeric or space.
.
  Localized decimal point.
,
  Localized thousand separator.
:
  Localized time separator.
/
  Localized date separator.
$
  Localized currency symbol.
<
  Converts characters that follow to lowercase.
>
  Converts characters that follow to uppercase.
|
  Disables case conversion.
\
  Escapes any character, turning it into a literal.
All others
  Literals.

The examples below demonstrates how to use the value and mask properties with the InputMask, InputDate, and InputTime controls.

HTML
<div class="app-input-group"> <label>Social Security Number</label> <input id="imSocial" title="Mask: 000-00-0000" /> </div> <div class="app-input-group"> <label>Phone Number</label> <input id="imPhone" title="Mask: (999) 000-0000" /> </div> <div class="app-input-group"> <label>Try your own</label> <input id="imCustomInput" /> <input id="imCustomTrial" /> </div> <div class="app-input-group"> <label>InputDate with Mask</label> <input id="imInputDate" title="Mask: 99/99/9999" /> </div> <div class="app-input-group"> <label>InputTime with Mask</label> <input id="imInputTime" title="Mask: 00:00 >LL" /> </div>
JS
// simple masks var socialSecurity = new wijmo.input.InputMask('#imSocial', { mask: '000-00-0000' }); var phoneNumber = new wijmo.input.InputMask('#imPhone', { mask: '(999) 000-0000' }); // try custom masks var customMaskTrial = new wijmo.input.InputMask('#imCustomTrial', { isRequired: false, placeholder: 'Try your input mask...' }); var customMaskInput = new wijmo.input.InputMask('#imCustomInput', { valueChanged: function (s, e) { customMaskTrial.mask = s.value; customMaskTrial.hostElement.title = 'Mask: ' + (s.value || 'N/A'); }, isRequired: false, placeholder: 'Enter an input mask...', value = null }); // use masks with input date and time controls var inputDate = new wijmo.input.InputDate('#imInputDate', { format: 'MM/dd/yyyy', mask: '99/99/9999' }); var inputTime = new wijmo.input.InputTime('#imInputTime', { format: 'hh:mm tt', step: 15, isEditable: true, mask: '00:00 >LL' });

#### Result (live):

Social Security Number
Phone Number
Try your own
InputDate with Mask
InputTime with Mask

## Menu

The Menu control allows you to create a simple drop-down list with clickable items. The Menu's items can be defined directly or by using the itemsSource property similar to the ComboBox. To specify the text displayed on the Menu, you can set the header property.

The Menu control offers two ways to handle user selections, specifying a command on each menu item and the itemClicked event. Unlike the itemClicked event, commands are objects that implement two methods:

- executeCommand(param): A method that executes the command.
- canExecuteCommand(param): A method that returns a Boolean value specifying whether or not the command can be executed. If the return value is false, the menu item is disabled automatically.

The example below demonstrates how to use both approaches.

HTML
<div class="app-input-group"> <label>itemClicked Event</label> <select id="mFileMenu"> <option>New: create a new document</option> <option>Open: load an existing document from a file</option> <option>Save: save the current document to a file</option> <option></option> <option>Exit: save changes and exit the application</option> </select> <select id="mEditMenu"> <option>Cut: move the current selection to the clipboard</option> <option>Copy: copy the current selection to the clipboard</option> <option>Paste: insert the clipboard content at the cursor position</option> <option></option> <option>Find: search the current document for some text</option> <option>Replace: replace occurrences of a string in the current document</option> </select> </div> <div class="app-input-group"> <label>Commands</label> <select id="mCmdMenu"> <option cmd-param=".25">+ 25%</option> <option cmd-param=".10">+ 10%</option> <option cmd-param=".05">+ 5%</option> <option cmd-param=".01">+ 1%</option> <option></option> <option cmd-param="-.01">- 1%</option> <option cmd-param="-.05">- 5%</option> <option cmd-param="-.10">- 10%</option> <option cmd-param="-.25">- 25%</option> </select> <input id="mInputNumber" type="text" /> </div>
JS
// simple menus with a common itemClicked handler var fileMenu = new wijmo.input.Menu('#mFileMenu', { header: 'File', itemClicked: itemClicked }); var editMenu = new wijmo.input.Menu('#mEditMenu', { header: 'Edit', itemClicked: itemClicked }); function itemClicked(s, e) { alert(wijmo.format('You selected option {selectedIndex} from the {header} menu!', s)); } // start with a 7% tax value var inputNumber = new wijmo.input.InputNumber('#mInputNumber', { value: 0.07, step: 0.05, format: 'p0', min: 0, max: 1 }); // use a command-based menu to update the tax var cmdMenu = new wijmo.input.Menu('#mCmdMenu', { header: 'Chance Tax', command: { executeCommand: function (arg) { arg = wijmo.changeType(arg, wijmo.DataType.Number); if (wijmo.isNumber(arg)) { inputNumber.value += arg; } }, canExecuteCommand: function (arg) { arg = wijmo.changeType(arg, wijmo.DataType.Number); if (wijmo.isNumber(arg)) { var val = inputNumber.value + arg; return val >= 0 && val <= 1; } return false; } } });

#### Result (live):

itemClicked Event
Commands