An input element. The type
attribute can be used to change the input type. All text input types are supported.
The component will automatically render as a Material Design input on Android devices.
Most attributes that can be used for a normal <input>
element can also be used on the <ons-input>
element.
In Onsen UI text input is provided by the <ons-input>
tag. It works exactly like the normal <input>
tag but with some small differences.
Just like the normal input tag you can use the type
attribute to define what kind of input that should be displayed. To get an number input you can use the number
type:
<ons-input
type="number"
placeholder="Age"
min="0"
max="200">
</ons-input>
You can also use types like number
or date
. The only exception are checkboxes and radio buttons, which are implemented in different elements.
For Android devices the input will displayed as a Material Design input element. One of the features of this input is that it can have a floating label which will animated when the user starts typing. Try changing the style to Android to see how it works.
The label is defined with the placeholder
attribute and to activate the animation the float
attribute is required.
<ons-input
placeholder="Username"
float>
</ons-input>
For normal input elements is possible to define a <label>
tab with the for
attribute to link it to an input element.
Unfortunately this does not work with custom elements like <ons-label>
so in order to do it we need to set the id
attribute of the inner input element. This is done using the input-id
attribute.
<label for="username">Username</label>
<ons-input input-id="username"></ons-input>
This work with any input in Onsen UI such as checkboxes, radios, etc.
modifier
attribute<ons-checkbox>
element is used to display a checkbox.<ons-radio>
element is used to display a radio button.<ons-range>
element is used to display a range slider.<ons-switch>
element is used to display a draggable toggle switch.<ons-select>
element is used to display a select box.Name | Type | Description |
---|---|---|
placeholder | String | Placeholder text. In Material Design, this placeholder will be a floating label. Optional. |
float | If this attribute is present, the placeholder will be animated in Material Design. Optional. | |
type | String |
Specify the input type. This is the same as the “type” attribute for normal inputs. It expects strict text types such as |
input-id | String |
Specify the “id” attribute of the inner <input> element. This is useful when using <label for="..."> elements.
Optional.
|
Name | Description |
---|---|
float | If this property is present, the placeholder will be animated in Material Design. |
value | The current value of the input. |
disabled | Whether the input is disabled or not. |
Name | Description |
---|---|
material | Displays a Material Design input. |
underbar | Displays a horizontal line underneath a text input. |
transparent | Displays a transparent input. Works for Material Design. |
Signature | Description |
---|---|
focus() | Focuses the input. |
blur() | Removes focus from the input. |
Focuses the input.
Removes focus from the input.
If you have any questions, use our Community Forum or talk to us on Discord chat. The Onsen UI team and your peers in the community will work together to help solve your issues.
For bug reports and feature requests use our GitHub Issues page.