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.
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
});
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.
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):
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.
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):
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.
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):
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.
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.
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):
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.
// 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', {
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):
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.
<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>
// 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;
}
}
});