Stepper
The stepper control lets the user adjust a value by increasing and decreasing it in small steps. Steppers are used in situations where a user needs to adjust a value by a small amount.
Basic Usage
The following example will render a simple Stepper with a label.
<label>
<input mbsc-stepper data-label="The label of the stepper" />
</label>
For being more informative a description and a color can also be passed to the switch.
<!-- Label and description for more info -->
<label>
<input mbsc-stepper data-label="Childrens" data-description="Number of childrens." />
</label>
<!-- Different color steppers -->
<label>
<input mbsc-stepper data-color="danger" data-label="Danger" />
</label>
<label>
<input mbsc-stepper color="info" label="Info" />
</label>
Auto initialization
If the component is added later to the DOM, e.g. with an Ajax page load, a custom function named enhance
needs to be called in order to initialize the dynamically added component.
When the enhance
function is called on a DOM element, all form elements will be initialized inside this element.
$.get('/myform', function (responseHtml) {
var $page = $('#page');
$page.html(responseHtml);
mobiscroll.enhance($page[0]);
});
Passing options
All the options can be passed to the stepper via data-
attributes with exceptions of the native input supported ones.
The attributes that the native html input supports can be passed directly without the data-
prefix. For example thevalue
or the disabled
attributes (and so on...).
In this example we pass the rtl and the disabled options:
<label>
<input mbsc-stepper data-rtl="true" value="10" disabled data-label="This is Disabled" />
</label>
Change value programmatically
<label>
<input id="my-stepper" value="5" mbsc-stepper data-label="Stepper value change" />
</label>
// get the input element, the stepper was initialized on
const inputElement = $('#my-stepper');
// get the instance of the stepper component
const stepperInstance = mobiscroll.getInst(inputElement);
const changeValueState = stepperInstance.value; // get the value as a number value
stepperInstance.value = 15; // will change the stepper value
Disabled state
The underlying input's disabled attribute will be taken into account at initialization time. For example:
<!-- This will create a disabled stepper -->
<label>
<input disabled mbsc-stepper data-label="Initially disabled" />
</label>
<!-- The following will not be disabled -->
<label>
<input mbsc-stepper data-label="Initially not disabled" />
</label>
Changing options dynamically
The options of the stepper can be changed dynamically using the setOptions
method on the instance itself, or the global setOptions
method.
Here is an example on how to change the disabled option on stepper:
<label>
<input id="my-stepper" disabled mbsc-stepper data-label="My stepper" />
</label>
// get the input element, the stepper was initialized on
const inputElement = $('#my-stepper');
// get the instance of the stepper component
const stepperInstance = mobiscroll.getInst(inputElement);
// set the disabled setting to false
stepperInstance.setOptions({ disabled: false });
Options
Name | Data attribute | Type | Default value | Description |
---|---|---|---|---|
color | data-color | String | undefined |
A predefined color to style the component. Supported values are:
|
description | data-description | String | undefined |
A description that shows up under the label of the component. |
disabled | data-disabled | Boolean | false |
Initial disabled state of the component. This will take no effect in inline display mode. |
label | data-label | String | undefined |
Sets the label of component. |
inputPosition | data-input-position | String | center |
Specify the input field position. It can be "start" , "end" or "center" .
|
max | data-max | Number | 100 |
Specify the maximum value that can be selected. |
min | data-min | Number | 0 |
Specify the minimum value that can be selected. |
step | data-step | Number | 1 |
Specify the step between values. |
rtl | data-rtl | Boolean | false |
Right to left display. |
theme | data-theme | String | undefined |
Sets the visual appearance of the component.
If it is
Make sure that the theme you set is included in the downloaded package.
|
themeVariant | data-theme-variant | String | undefined |
Controls which variant of the theme will be used (light or dark). Possible values:
To use the option with custom themes, make sure to create two custom themes,
where the dark version has the same name as the light one, suffixed with |
value | data-value | Number | 0 |
Specify the value of the stepper. |
Customizing the appearance
While the provided pre-built themes are enough in many use cases, most of the times on top of adapting to a specific platform, you'd also like to match a brand or color scheme. Mobiscroll provides various ways to achieve this:
- Create custom themes using the theme builder - the custom themes can be also built using out theme builder, on a graphical user interface, without any coding, or the need for Sass support in your project.
- Create custom themes using Sass - use this, if you need multiple themes with different color variatons, in case you have pages with different colors, or you'd like to users to customize the colors of your app.
- Override the Sass color variables - the straightforward way to change the colors in one place throughout the application.
Override the Sass Color Variables
A convenient way to customize the colors of the Mobiscroll components is to override the Sass color variables.
Let's say your branding uses a nice red accent color, and you'd like that color to appear on the Mobiscroll components as well,
while still using platform specific themes (e.g. ios
on iOS devices, material
on Android devices, and mobiscroll
on desktop).
You can override the accent color for every theme:
$mbsc-ios-accent: #e61d2a;
$mbsc-material-accent: #e61d2a;
$mbsc-mobiscroll-accent: #e61d2a;
@import "~@mobiscroll/JQuery/dist/css/mobiscroll.jquery.scss"
You can also customize the colors on many levels:
- Theme specific variables (ex.
$mbsc-material-background
,$mbsc-ios-dark-text
) are applied to all components in a theme. Complete list of variables here. - Component specific global variables (ex.
$mbsc-card-background-light
,$mbsc-listview-text-dark
) are applied to all themes for a specific component. - Component and theme specific variables (ex.
$mbsc-ios-dark-form-background
,$mbsc-material-input-text
) are applied to a specific theme and a specific component.