Using Range Slider Control In Onsen UI Using Visual Studio 2015

Before reading this article, please go through the article links, mentioned below.

Apache Cordova

Apache Cordova is an open-source project that aims at allowing mobile developers to build applications for all the major mobile platforms, using HTML, CSS, and JavaScript technologies.

Monaca

Monaca is a software tool and service solution for building and deploying HTML5 mobile hybrid apps. It is built on top of an open-source Apache Cordova. Monaca provides a full suite of resources including Cloud IDE, local development tools, debugger, and back-end support.

Monaca's cloud-based IDE builds HTML5 hybrid mobile apps for iOS, Android, Windows, and Chrome apps, using HTML, CSS, and JavaScript.

Monaca CLI provides Onsen UI templates, device debugger, remote building, and any service that you might need directly from your terminal.

Onsen UI Framework

Onsen UI is a front-end UI framework to develop cross-platform mobile apps, using Apache Cordova and PhoneGap. It’s fully independent of frameworks and you can easily plug these components into any project, regardless of JavaScript framework.

Onsen UI templates can be used with Visual Studio 2015. All the templates are compatible with Visual Studio Tools for Apache Cordova. It works pretty well with UWP, iOS, and Android apps.

Building Range Slider with Onsen UI Framework

The <ons-range> element is used to display a Range Slider. For setting the maximum and minimum value, we use "min" and "max" attributes. The "step" attribute is used to change the value in every step.

It can be disabled using the "disabled" attribute.

Let’s see how to start building the app using Range Slider in Onsen UI Framework and Visual Studio 2015.

Prerequisites

  • Visual Studio 2015.
  • Visual Studio Tools for Apache Cordova.

Follow the steps, mentioned below, to build an Onsen UI with Range Slider, using Onsen UI Framework.

Step 1. Create an Onsen UI App

Let’s be ready to create a new project. Open Visual Studio 2015 and click the File -> New -> Project option for the New Apache Cordova app, using Onsen UI Framework.

 UI App

Step 2. Give the Project a name

A "New Project" window will open. Select Installed -> Template -> JavaScript -> Manoca ->Onsen UI Blank app.

Type the Project name Onsen UI RangeSlider and click the OK button.

Project a name

Step 3. The main screen is shown below.

 Main screen

Step 4. Afterwards, we create the project. Our solution should resemble what is shown below.

Project

This table gives the basic idea of how we might use each one.

File Why is it in your project?
Merge Folder It contains the package for Android, iOS, and Windows apps.
www This file contains the images, library, and JS files.
config.xml Contains the settings of our app.
taco.json Defines which version of Cordova CLI Visual Studio is used to build the project.

Step 5. Adding the Range Slider Control

Go to index.html in the Solution Bar and add HTML coding. We can add our own HTML code in between <body> tags.

Slider Control

Apply range slider control

Go to index.html in the Solution Bar and add HTML code.

Explanation
 

Coding Explanation
<ons-page> Create a Page
<ons-toolbar> Add the Toolbar
<ons-row> Create the row
<ons-col> Create the column
<ons-icon icon="md-volume-down"> Add the icon-Volume down
<ons-range style="width: 100%;" value="25"> Add the Range control
<ons-icon icon="md-volume-up"> Add the icon-Volume up
<ons-icon icon="md-brightness-low"> Add the icon-brightness low
<ons-icon icon="md-brightness-high"> Add the icon-brightness high
<ons-icon icon="md-thumb-down"> Add the icon-thumb down
<ons-icon icon="md-thumb-up"> Add the icon-thumb up
<ons-range disabled style="width: 100%;" value="75"> Add range with Disabled mode

Coding

<ons-page>

    <ons-toolbar>
        <div class="center">Range sliders</div>
    </ons-toolbar>

    <p>
        <ons-row>
            <ons-col width="40px" style="text-align: center; line-height: 31px;">
                <ons-icon icon="md-volume-down"></ons-icon>
            </ons-col>

            <ons-col>
                <ons-range style="width: 100%;" value="25"></ons-range>
            </ons-col>

            <ons-col width="40px" style="text-align: center; line-height: 31px;">
                <ons-icon icon="md-volume-up"></ons-icon>
            </ons-col>
        </ons-row>

        <ons-row style="margin-top: 20px;">

            <ons-col width="40px" style="text-align: center; line-height: 31px;">
                <ons-icon icon="md-brightness-low"></ons-icon>
            </ons-col>

            <ons-col>
                <ons-range style="width: 100%;" value="50"></ons-range>
            </ons-col>

            <ons-col width="40px" style="text-align: center; line-height: 31px;">
                <ons-icon icon="md-brightness-high"></ons-icon>
            </ons-col>
        </ons-row>

        <ons-row style="margin-top: 20px;">

            <ons-col width="40px" style="text-align: center; line-height: 31px;">
                <ons-icon icon="md-thumb-down"></ons-icon>
            </ons-col>

            <ons-col>
                <ons-range disabled style="width: 100%;" value="75"></ons-range>
            </ons-col>

            <ons-col width="40px" style="text-align: center; line-height: 31px;">
                <ons-icon icon="md-thumb-up"></ons-icon>
            </ons-col>
        </ons-row>
    </p>

</ons-page>

HTML

Index

Style

Step 6. Run the application

Now, we are ready to run our Project. Thus, click Ripple – Nexus (Galaxy) to run the application. (Apache Ripple is a free mobile simulator).

 Ripple – Nexus

Output 1. The main screen is given below.

Screen

Output 2. Move the Slider, as shown below.

Move the Slider

Conclusion

I hope you understand how to start the Range Slider Control in Onsen UI, using Visual Studio 2015 and how to run it.


Similar Articles