Wijmo

Input 101 (Vue)

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

Getting Started

Steps for getting started with Input controls in Vue applications:

  1. Add references to Vue, Wijmo, and Wijmo's Vue interop module.
  2. Create a Vue object and give it a host element.
  3. Add Input controls to Vue's host element and bind them to the data.
<!DOCTYPE html> <html> <head> <!-- Vue --> <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.26/vue.min.js"></script> <!-- Wijmo --> <link href="https://cdn.grapecity.com/wijmo/5.latest/styles/wijmo.min.css" rel="stylesheet"/> <script src="https://cdn.grapecity.com/wijmo/5.latest/controls/wijmo.min.js"></script> <script src="https://cdn.grapecity.com/wijmo/5.latest/controls/wijmo.input.min.js"></script> <!-- Wijmo/Vue interop --> <script src="https://cdn.grapecity.com/wijmo/5.latest/interop/vue/wijmo.vue.min.js"></script> <!-- app scripts and styles --> <link href="styles/app.css" rel="stylesheet" /> <script src="scripts/app.js"></script> </head> <body> <div id="app"> <wj-input-number :value.sync="someValue" :step=".5" format="n"> </wj-input-number> <br /> value: {​{ someValue | wj-format 'n2' }} </div> </body> </html>
// Vue application var app = new Vue({ el: '#app', data: { someValue: 123 }, });

Result (live):


value: {{ someValue | wj-format 'n2' }}

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.

<div class="app-input-group"> <label>itemsSource Only</label> <wj-auto-complete :items-source="countries" :is-required="false" placeholder="(country)"></wj-auto-complete> </div> <div class="app-input-group"> <label>itemsSource & cssMatch</label> <wj-auto-complete :items-source="countries" :is-required="false" css-match="highlight" placeholder="(country)"></wj-auto-complete> </div>
// Vue application var app = new Vue({ el: '#app', data: { someValue: 123, countries: getCountries() }, });

Result (live):

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.

<div class="app-input-group"> <label>Non-Editable</label> <wj-combo-box :items-source="countries" :is-editable="false"> </wj-combo-box> </div> <div class="app-input-group"> <label>Editable</label> <wj-combo-box :items-source="countries" :is-editable="true"> </wj-combo-box> </div>
// Vue application var app = new Vue({ el: '#app', data: { someValue: 123, countries: getCountries() }, });

Result (live):

InputDate and 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:

The example below demonstrates how to use these properties.

In addition to these basic properties, the Calendar control has a formatItem event that you can use to customize the display of specific days in the calendar. The sample below uses this event to customize the appearance of weekends and holidays.

<div class="app-input-group"> <label>Bound InputDate with min & max</label> <wj-input-date :value.sync="theDate" :min="minDate" :max="maxDate"> </wj-input-date> </div> <div class="app-input-group"> <label>Bound Calendar with min & max</label> <wj-calendar style="width:300px;" :value.sync="theDate" :min="minDate" :max="maxDate" :format-item="formatItem"> </wj-calendar> </div> <p> <b>Selected Date: {​{ theDate | wj-format 'd' }}</b> </p> <p> <b>Valid Range: {​{ minDate | wj-format 'd' }} to {{ maxDate | wj-format 'd' }}</b> </p>
// Vue application var app = new Vue({ el: '#app', data: { someValue: 123, countries: getCountries(), theDate: new Date(today.getFullYear(), today.getMonth(), today.getDate(), 13, 30), minDate: new Date(today.getFullYear(), 0, 1), maxDate: new Date(today.getFullYear(), 11, 31) }, });

Result (live):

Selected Date: {{ theDate | wj-format 'd' }}

Valid Range: {{ minDate | wj-format 'd' }} to {{ maxDate | wj-format 'd' }}

InputDate, InputTime and InputDateTime Controls

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 InputDateTime control combines the InputDate and InputTime controls, allowing you to set the date and time portions of a JavaScript date. The InputDateTime control has two drop-downs: a Calendar for picking dates, and a list for picking times.

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 JavaScript Date object and only update the part of the DateTime that they are responsible for.

The example also shows an InputDateTime that updates both the date and time parts of the JavaScript Date object.

<div class="app-input-group"> <label>Bound InputDate with min, max, & format</label> <wj-input-date :value.sync="theDate" :min="minDate" :max="maxDate" format="MMM dd, yyyy"> </wj-input-date> </div> <div class="app-input-group"> <label>Bound InputTime with min, max, & step</label> <wj-input-time :value.sync="theDate" :step="15" min="09:00" max="17:00"> </wj-input-time> </div> <div class="app-input-group"> <label>Bound InputDateTime with min, max, format, and step</label> <wj-input-date-time :value.sync="theDate" format="MMM dd, yyyy hh:mm tt" :min="minDate" :max="maxDate" :time-step="15" time-min="09:00" time-max="17:00"> </wj-input-date-time> </div> <p> <b>Selected Date & Time: {​{ theDate | wj-format 'f' }}</b> </p>
// Vue application var app = new Vue({ el: '#app', data: { theDate: new Date(today.getFullYear(), today.getMonth(), today.getDate(), 13, 30), minDate: new Date(today.getFullYear(), 0, 1), maxDate: new Date(today.getFullYear(), 11, 31), ... } });

Result (live):

Selected Date & Time: {{ theDate | wj-format 'f' }}

InputDate and Validation

The InputDate control automatically parses dates typed in by the user using the format specified by the format property. Invalid dates are ignored and the original value is preserved. The InputDate control also checks the range and ensures that date values are between the values specified by the min and max properties.

But in many cases, not all dates between the min and max properties are valid. For example, you may be creating an appointment scheduler application and want to ensure that users don't schedule appointments for weekends, holidays, or dates that already have a certain number of appointments scheduled.

To handle these situations, the InputDate (and the Calendar) have an itemValidator property. This property represents a function that takes a date as a parameter and returns true if the date is valid for selection, or false otherwise. Invalid dates will automatically be disabled and users will not be able to select them in the calendar or to enter them by typing.

The example below demonstrates this with an InputDate that has an itemValidator function that returns false for weekends and US federal holidays. The example also uses an itemFormatter function to add some special formatting and a tooltip with the name of the holidays.

<wj-input-date :value="theDate" :item-formatter="itemFormatter" :item-validator="itemValidator"> </wj-input-date>
// Vue application var app = new Vue({ el: '#app', data: { theDate: new Date(today.getFullYear(), today.getMonth(), today.getDate(), 13, 30), }, methods: { // format and validate dates itemFormatter: function (date, element) { var weekday = date.getDay(), holiday = getHoliday(date); wijmo.toggleClass(element, 'date-weekend', weekday == 0 || weekday == 6); wijmo.toggleClass(element, 'date-holiday', holiday); element.title = holiday; }, itemValidator: function (date) { switch (date.getDay()) { case 0: case 6: return false; // no appointments on weekends } if (getHoliday(date).length > 0) { return false; // no appointments on holidays } return true; // not a weekend or a holiday, this date is OK } } });

Result (live):

Selected Date: {{ theDate | wj-format 'd' }}

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 displays the control's selectedIndex and selectedValue properties.

<wj-list-box style="width:250px;height:150px;" :items-source="countries" control="listBox"> </wj-list-box> <p> <b>selectedIndex: {​{ listBox.selectedIndex }}</b> </p> <p> <b>selectedValue: {​{ listBox.selectedValue }}</b> </p>
// Vue application var app = new Vue({ el: '#app', data: { countries: getCountries(), listBox: null // will receive a reference to the ListBox control }, });

Result (live):

selectedIndex: {{ listBox.selectedIndex }}

selectedValue: {{ listBox.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:

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

<div class="app-input-group"> <label>Unbound with "n0" format</label> <wj-input-number format="n0"> </wj-input-number> </div> <div class="app-input-group"> <label>Bound with "n" format</label> <wj-input-number :value.sync="price" format="n"> </wj-input-number> </div> <div class="app-input-group"> <label>Bound with min (0), max (10), step, and "c2" format</label> <wj-input-number :value.sync="price" format="c2" :step=".5" :min="0" :max="10"> </wj-input-number> </div> <div class="app-input-group"> <label>Unbound with placeholder and isRequired="false"</label> <wj-input-number placeholder="Enter a number..." :is-required="false" :value="nullVal"> </wj-input-number> </div>
// Vue application var app = new Vue({ el: '#app', data: { price: 3.5, nullVal: 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.

<div class="app-input-group"> <label>Social Security Number</label> <wj-input-mask mask="000-00-0000" title="Mask: 000-00-0000"> </wj-input-mask> </div> <div class="app-input-group"> <label>Phone Number</label> <wj-input-mask mask="(999) 000-0000" title="Mask: (999) 000-0000"> </wj-input-mask> </div> <div class="app-input-group"> <label>Try your own</label> <wj-input-mask :value.sync="customMask" :is-required="false" placeholder="Enter an input mask..."> </wj-input-mask> <wj-input-mask :mask="customMask" title="Mask: {{ customMask || 'N/A' }}"> </wj-input-mask> </div> <div class="app-input-group"> <label>InputDate with mask</label> <wj-input-date :value.sync="theDate" format="MM/dd/yyyy" mask="99/99/9999" title="Mask: 99/99/9999"> </wj-input-date> </div> <div class="app-input-group"> <label>InputTime with mask</label> <wj-input-time :value.sync="theDate" format="hh:mm tt" :is-editable="true" :step="15" mask="00:00 >LL" title="Mask: 00:00 >LL"> </wj-input-time> </div>
// Vue application var app = new Vue({ el: '#app', data: { theDate: new Date(today.getFullYear(), today.getMonth(), today.getDate(), 13, 30), customMask: '', ... } });

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:

In most cases, the command methods should be bound to the Vue application, so they have access to the application state. This can be done in the application's ready hook as shown in the example below:

<div class="app-input-group"> <label>itemClicked Event</label> <wj-menu header="File" :items-source="fileMenuOptions" :item-clicked="menuItemClicked"> </wj-menu> <wj-menu header="Edit" :items-source="editMenuOptions" :item-clicked="menuItemClicked"> </wj-menu> </div> <div class="app-input-group"> <label>Commands</label> <wj-menu header="Change Tax" display-member-path="text" :items-source="taxMenuOptions" :command="taxMenuCommand" command-parameter-path="parm"> </wj-menu> <wj-input-number :value.sync="tax" :min="0" :max="1" :step=".05" format="p0"> </wj-input-number> </div> </div>
// Vue application var app = new Vue({ el: '#app', data: { tax: 0.08, fileMenuOptions: [ '<i class="fa fa-file-o"></i>&nbsp;&nbsp;<b>New</b><br><small><i>create a new file</i></small>', '<i class="fa fa-folder-open-o"></i>&nbsp;&nbsp;<b>Open</b><br><small><i>open an existing file or folder</i></small>', '<i class="fa fa-save"></i>&nbsp;&nbsp;<b>Save</b><br><small><i>save the current file</i></small>', '<span class="wj-separator"></span>', '<i class="fa fa-times"></i>&nbsp;&nbsp;<b>Exit</b><br><small><i>exit the application</i></small>' ], editMenuOptions: [ '<i class="fa fa-cut"></i>&nbsp;&nbsp;<b>Cut</b><br><small><i>move the current selection to the clipboard</i></small>', '<i class="fa fa-copy"></i>&nbsp;&nbsp;<b>Copy</b><br><small><i>copy the current selection to the clipboard</i></small>', '<i class="fa fa-paste"></i>&nbsp;&nbsp;<b>Paste</b><br><small><i>insert clipboard content at the cursor position</i></small>' ], taxMenuOptions: [ { text: '+ 25%', parm: .25 }, { text: '+ 10%', parm: .10 }, { text: '+ 5%', parm: .05 }, { text: '+ 1%', parm: .01 }, { text: '<span class="wj-separator"></span>' }, { text: '- 1%', parm: -.01 }, { text: '- 5%', parm: -.05 }, { text: '- 10%', parm: -.10 }, { text: '- 25%', parm: -.25 } ], // tax menu command taxMenuCommand: { executeCommand: function (arg) { if (wijmo.isNumber(arg)) { this.tax += arg; } }, canExecuteCommand: function(arg) { if (wijmo.isNumber(arg)) { var val = this.tax + arg; return val >= 0 && val <= 1; } return false; } } }, methods: { menuItemClicked: function (s, e) { alert('You\'ve selected option ' + s.selectedIndex + ' from the ' + s.header + ' menu!'); } }, created: function () { // bind the menu commands to the app instance var cmd = this.taxMenuCommand; cmd.executeCommand = cmd.executeCommand.bind(this); cmd.canExecuteCommand = cmd.canExecuteCommand.bind(this); } });

Result (live):

Dialogs and Popups

The Popup control can be used to display arbitrary content as dialogs (AKA modals, centered on the screen, without an owner element), or as popups (AKA popovers, located relative to an owner element).

Dialogs

Click the buttons below to see dialogs:

<p> Click to see a modal dialog: <button type="button" class="btn" @click="modalDialog.show()"> Click </button> </p> <wj-popup control="modalDialog" :modal="true" hide-trigger="None"> <wj-include src="includes/dialog.htm"></wj-include> </wj-popup> <p> Click to see a modeless dialog: <button type="button" class="btn" @click="modelessDialog.show()"> Click </button> </p> <wj-popup control="modelessDialog" :modal="false"> <wj-include src="includes/dialog.htm"></wj-include> </wj-popup>
// no code required

Click to see a modal dialog:

Click to see a modeless dialog:

Popups/popovers

Click the buttons below to see popovers:

<p> Click to open, move focus away to close: <button id="btn1" type="button" class="btn"> Click </button> </p> <wj-popup class="popover" owner="#btn1" :show-trigger="Click" hide-trigger="Blur"> <wj-include src="includes/popup.htm"></wj-include> </wj-popup> <p> Click to open, click again to close: <button id="btn2" type="button" class="btn"> Click </button> </p> <wj-popup class="popover" owner="#btn2" :show-trigger="Click" hide-trigger="Click"> <wj-include src="includes/popup.htm"></wj-include> </wj-popup> <p> Click to open, click close button on popup to close: <button id="btn3" type="button" class="btn"> Click </button> </p> <wj-popup class="popover" owner="#btn3" :show-trigger="Click" hide-trigger="None"> <wj-include src="includes/popup.htm"></wj-include> </wj-popup>
// no code required

Click to open, move focus away to close:

Click to open, click again to close:

Click to open, click close button on popup to close: