CoderFunda
  • Home
  • About us
    • Contact Us
    • Disclaimer
    • Privacy Policy
    • About us
  • Home
  • Php
  • HTML
  • CSS
  • JavaScript
    • JavaScript
    • Jquery
    • JqueryUI
    • Stock
  • SQL
  • Vue.Js
  • Python
  • Wordpress
  • C++
    • C++
    • C
  • Laravel
    • Laravel
      • Overview
      • Namespaces
      • Middleware
      • Routing
      • Configuration
      • Application Structure
      • Installation
    • Overview
  • DBMS
    • DBMS
      • PL/SQL
      • SQLite
      • MongoDB
      • Cassandra
      • MySQL
      • Oracle
      • CouchDB
      • Neo4j
      • DB2
      • Quiz
    • Overview
  • Entertainment
    • TV Series Update
    • Movie Review
    • Movie Review
  • More
    • Vue. Js
    • Php Question
    • Php Interview Question
    • Laravel Interview Question
    • SQL Interview Question
    • IAS Interview Question
    • PCS Interview Question
    • Technology
    • Other

15 January, 2019

JqueryUI - Spinner

 Programing Coderfunda     January 15, 2019     JqueryUI, JqueryUI - Spinner     No comments   

JqueryUI - Spinner, JqueryUI, 

Spinner widget adds a up/down arrow to the left of a input box thus allowing a user to increment/decrement a value in the input box. It allows users to type a value directly, or modify an existing value by spinning with the keyboard, mouse or scrollwheel. It also has a step feature to skip values. In addition to the basic numeric features, it also enables globalized formatting options (ie currency, thousand separator, decimals, etc.) thus providing a convenient internationalized masked entry box.
The following example depends on Globalize. You can get the Globalize files from https://github.com/jquery/globalize. Click the releases link, select the version you want, and download the .zip or tar.gz file. Extract the files and copy the following files to the folder where your example is located.
  • lib/globalize.js : This file contains the Javascript code for dealing with localizations
  • lib/globalize.culture.js : This file contains a complete set of the locales that the Globalize library comes with.
These files are also present in the external folder of your jquery-ui library.
jQueryUI provides spinner() method which creates a spinner.

Syntax

The spinner() method can be used in two forms −
  • $(selector, context).spinner (options) Method
  • $(selector, context).spinner ("action", params) Method

$ (selector, context).spinner (options) Method

The spinner (options) method declares that an HTML element and its contents should be treated and managed as spinner. The options parameter is an object that specifies the appearance and behavior of the spinner elements involved.

Syntax

$(selector, context).spinner (options);
You can provide one or more options at a time using Javascript object. If there are more than one options to be provided then you will separate them using a comma as follows −
$(selector, context).spinner({option1: value1, option2: value2..... });
The following table lists the different options that can be used with this method −
Sr.No.Option & Description
1culture This option sets the culture to use for parsing and formatting the value. By default its value is null which means the currently set culture in Globalize is used.
2disabled This option if set to true disables spinner. By default its value is false.
3icons This option sets icons to use for buttons, matching an icon provided by the jQuery UI CSS Framework. By default its value is { down: "ui-icon-triangle-1-s", up: "ui-icon-triangle-1-n" }.
4incremental This option controls the number of steps taken when holding down a spin button. By default its value is true.
5max This option indicates the maximum allowed value. By default its value is null which means there is no maximum enforced.
6min This option indicates the minimum allowed value. By default its value is null which means there is no minimum enforced.
7numberFormat This option indicates format of numbers passed to Globalize, if available. Most common are "n" for a decimal number and "C" for a currency value. By default its value is null.
8page This option indicates the number of steps to take when paging via the pageUp/pageDown methods. By default its value is 10.
9step This option indicates size of the step to take when spinning via buttons or via the stepUp()/stepDown() methods. The element's step attribute is used if it exists and the option is not explicitly set.
The following section will show you a few working examples of spinner widget functionality.

Default Functionality

The following example demonstrates a simple example of spinner widget functionality, passing no parameters to the spinner() method.
<!doctype html>
<html lang = "en">
<head>
<meta charset = "utf-8">
<title>jQuery UI Spinner functionality</title>
<link href = "https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css"
rel = "stylesheet">
<script src = "https://code.jquery.com/jquery-1.10.2.js"></script>
<script src = "https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

<!-- CSS -->
<style type = "text/css">
#spinner-1 input {width: 100px}
</style>
<!-- Javascript -->
<script>
$
(function() {
$
( "#spinner-1" ).spinner();
});
</script>
</head>

<body>
<!-- HTML -->
<div id = "example">
<input type = "text" id = "spinner-1" value = "0" />
</div>
</body>
</html>
Let us save the above code in an HTML file spinnerexample.htm and open it in a standard browser which supports javascript, you must also see the following output. Now, you can play with the result −

Use of Min, Max and Step Options

The following example demonstrates the usage of three options min, max and step in the spinner widget of JqueryUI.
<!doctype html>
<html lang = "en">
<head>
<meta charset = "utf-8">
<title>jQuery UI Spinner functionality</title>
<link href = "https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css"
rel = "stylesheet">
<script src = "https://code.jquery.com/jquery-1.10.2.js"></script>
<script src = "https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

<!-- CSS -->
<style type = "text/css">
#spinner-2,#spinner-3 input {width: 100px}
</style>
<!-- Javascript -->
<script>
$
(function() {
$
( "#spinner-2" ).spinner({
min
: -10,
max
: 10
});
$
('#spinner-3').spinner({
step
: 100,
min
: -1000000,
max
: 1000000
});
});
</script>
</head>

<body>
<!-- HTML -->
<div id = "example">
Spinner Min, Max value set:
<input type = "text" id = "spinner-2" value = "0" /><br><br>
Spinner increments/decrements in step of of 100:
<input type = "text" id = "spinner-3" value = "0" />
</div>
</body>
</html>
Let us save the above code in an HTML file spinnerexample.htm and open it in a standard browser which supports javascript, you must also see the following output. Now, you can play with the result −
In the above example, you can see in the first spinner the max and min values are set to 10 and -10 respectively. Hence crossing these values, the spinner will stop incrementing/decrementing. In the second spinner the spinner value increments/decrements in steps of 100.

Use of icons Option

The following example demonstrates the usage of option icons in the spinner widget of JqueryUI.
<!doctype html>
<html lang = "en">
<head>
<meta charset = "utf-8">
<title>jQuery UI Spinner functionality</title>
<link href = "https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css"
rel = "stylesheet">
<script src = "https://code.jquery.com/jquery-1.10.2.js"></script>
<script src = "https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

<!-- CSS -->
<style type = "text/css">
#spinner-5 input {width: 100px}
</style>
<!-- Javascript -->
<script>
$
(function() {
$
( "#spinner-5" ).spinner({
icons
: {
down
: "custom-down-icon", up: "custom-up-icon"
}
});
});
</script>
</head>

<body>
<!-- HTML -->
<div id = "example">
<input type = "text" id = "spinner-5" value = "0" />
</div>
</body>
</html>
Let us save the above code in an HTML file spinnerexample.htm and open it in a standard browser which supports javascript, you must also see the following output. Now, you can play with the result −
In the above example, you can notice the images spinner are changed.

Use of culture, numberFormat, and page options

The following example demonstrates the usage of three options culture, numberFormat and page in the spinner widget of JqueryUI.
<!doctype html>
<html lang = "en">
<head>
<meta charset = "utf-8">
<title>jQuery UI Spinner functionality</title>
<link href = "https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css"
rel = "stylesheet">
<script src = "https://code.jquery.com/jquery-1.10.2.js"></script>
<script src = "https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<script src = "/jqueryui/jquery-ui-1.10.4/external/jquery.mousewheel.js"></script>
<script src = "/jqueryui/jquery-ui-1.10.4/external/globalize.js"></script>
<script src = "/jqueryui/jquery-ui-1.10.4/external/globalize.culture.de-DE.js"></script>

<script>
$
(function() {
$
( "#spinner-4" ).spinner({
culture
:"de-DE",
numberFormat
:"C",
step
:2,
page
:10
});
});
</script>
</head>

<body>
<p>
<label for = "spinner-4">Amount to donate:</label>
<input id = "spinner-4" name = "spinner" value = "5">
</p>

</body>
</html>
Let us save the above code in an HTML file spinnerexample.htm and open it in a standard browser which supports javascript, you must also see the following output. Now, you can play with the result −
In the above example, you can see the spinner displays the number in currency format as the numberFormat is set to "C" and culture is set to "de-DE". Here we have used the Globalize files from the jquery-ui library.

$ (selector, context).spinner ("action", params) Method

The spinner ("action", params) method can perform an action on spinner elements, such as enabling/disabling the spinner. The action is specified as a string in the first argument (e.g., "disable" disables the spinner). Check out the actions that can be passed, in the following table.

Syntax

$(selector, context).spinner ("action", params);;
The following table lists the different actions that can be used with this method −
Sr.No.Action & Description
1destroy This action destroys the spinner functionality of an element completely. The elements return to their pre-init state. This method does not accept any arguments.
2disable This action disables the spinner functionality. This method does not accept any arguments.
3enable This action enables the spinner functionality. This method does not accept any arguments.
4option( optionName ) This action gets the value currently associated with the specified optionName. Where optionName is the name of the option to get.
5option This action gets an object containing key/value pairs representing the current spinner options hash. This method does not accept any arguments.
6option( optionName, value ) This action sets the value of the spinner option associated with the specified optionName.
7option( options ) This action sets one or more options for the spinner.
8pageDown( [pages ] ) This action decrements the value by the specified number of pages, as defined by the page option.
9pageUp( [pages ] ) This action increments the value by the specified number of pages, as defined by the page option.
10stepDown( [steps ] ) This action decrements the value by the specified number of steps.
11stepUp( [steps ] ) This action increments the value by the specified number of steps.
12value This action gets the current value as a number. The value is parsed based on the numberFormat and culture options. This method does not accept any arguments.
13value( value ) This action sets the value. if value is passed value is parsed based on the numberFormat and culture options.
14widget This action returns the spinner widget element; the one annotated with the ui-spinner class name.
The following examples demonstrate how to use the actions given in the above table.

Use of action stepUp, stepDown, pageUp, and pageDown

The following example demonstrates the use of stepUp, stepDown, pageUp and pageDown methods.
<!doctype html>
<html lang = "en">
<head>
<meta charset = "utf-8">
<title>jQuery UI Spinner functionality</title>
<link href = "https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css"
rel = "stylesheet">
<script src = "https://code.jquery.com/jquery-1.10.2.js"></script>
<script src = "https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

<!-- CSS -->
<style type = "text/css">
#spinner-6 input {width: 100px}
</style>

<!-- Javascript -->
<script>
$
(function() {
$
("#spinner-6").spinner();
$
('button').button();

$
('#stepUp-2').click(function () {
$
("#spinner-6").spinner("stepUp");
});

$
('#stepDown-2').click(function () {
$
("#spinner-6").spinner("stepDown");
});

$
('#pageUp-2').click(function () {
$
("#spinner-6").spinner("pageUp");
});

$
('#pageDown-2').click(function () {
$
("#spinner-6").spinner("pageDown");
});
});
</script>
</head>

<body>
<!-- HTML -->
<input id = "spinner-6" />
<br/>
<button id = "stepUp-2">Increment</button>
<button id = "stepDown-2">Decrement</button>
<button id = "pageUp-2">Increment Page</button>
<button id = "pageDown-2">Decrement Page</button>
</body>
</html>
Let us save the above code in an HTML file spinnerexample.htm and open it in a standard browser which supports javascript, you also must see the following output −
In the above example, use the respective buttons to increment/decrement the spinner.

Use of action enable, and disable

The following example demonstrates the use of enable and disable methods.
<!doctype html>
<html lang = "en">
<head>
<meta charset = "utf-8">
<title>jQuery UI Spinner functionality</title>
<link href = "https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css"
rel = "stylesheet">
<script src = "https://code.jquery.com/jquery-1.10.2.js"></script>
<script src = "https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

<!-- CSS -->
<style type = "text/css">
#spinner-7 input {width: 100px}
</style>

<!-- Javascript -->
<script>
$
(function() {
$
("#spinner-7").spinner();
$
('button').button();
$
('#stepUp-3').click(function () {
$
("#spinner-7").spinner("enable");
});
$
('#stepDown-3').click(function () {
$
("#spinner-7").spinner("disable");
});
});
</script>
</head>

<body>
<!-- HTML -->
<input id = "spinner-7" />
<br/>
<button id = "stepUp-3">Enable</button>
<button id = "stepDown-3">Disable</button>
</body>
</html>
Let us save the above code in an HTML file spinnerexample.htm and open it in a standard browser which supports javascript, you must also see the following output −
In the above example, use the Enable/Disable buttons to enable or disable the spinner.

Event Management on Spinner Elements

In addition to the spinner (options) method which we saw in the previous sections, JqueryUI provides event methods which gets triggered for a particular event. These event methods are listed below −
Sr.No.Event Method & Description
1change(event, ui) This event is triggered when the value of the spinner has changed and the input is no longer focused.
2create(event, ui) This event is triggered when the spinner is created.
3spin(event, ui) This event is triggered during increment/decrement.
4start(event, ui) This event is triggered before a spin. Can be canceled, preventing the spin from occurring.
5stop(event, ui) This event is triggered after a spin.

Example

The following example demonstrates the event method usage in spinner widgets. This example demonstrates the use of events spin, change and stop.
<!doctype html>
<html lang = "en">
<head>
<meta charset = "utf-8">
<title>jQuery UI Spinner functionality</title>
<link href = "https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css"
rel = "stylesheet">
<script src = "https://code.jquery.com/jquery-1.10.2.js"></script>
<script src = "https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

<!-- CSS -->
<style type = "text/css">
#spinner-8 input {width: 100px}
</style>

<!-- Javascript -->
<script>
$
(function() {
$
( "#spinner-8" ).spinner({
spin
: function( event, ui ) {
var result = $( "#result-2" );
result
.append( "Spin Value: "+$( "#spinner-8" ).spinner("value") );
},
change
: function( event, ui ) {
var result = $( "#result-2" );
result
.append( "Change value: "+$( "#spinner-8" ).spinner("value") );
},
stop
: function( event, ui ) {
var result = $( "#result-2" );
result
.append( "Stop value: "+$( "#spinner-8" ).spinner("value") );
}
});
});
</script>
</head>

<body>
<!-- HTML -->
<div id = "example">
<input type = "text" id = "spinner-8" value = "0" />
</div>
<span id = "result-2"></span>
</body>
</html>
Let us save the above code in an HTML file spinnerexample.htm and open it in a standard browser which supports javascript, you must also see the following output −
In the above example change the value of the spinner and see, the messages being displayed below for spin and stop events. Now change the focus of the spinner and you see a message being displayed on change event.

Extension Points

The spinner widget is built with the widget factory and can be extended. To extend widgets, we can either override or add to the behavior of existing methods. Following method provides as extension point with the same API stability as the spinner methods. Listed in the above table.
Sr.No.Method & Description
1_buttonHtml(event) This method return a String which is an HTML. This HTML can be used for the spinner's increment and decrement buttons. Each button must be given a ui-spinner-button class name for the associated events to work. This method does not accept any arguments.
2_uiSpinnerHtml(event) This method determine the HTML to use to wrap the spinner's <input> element. This method does not accept any arguments.
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to XShare to Facebook
Newer Post Older Post Home

0 comments:

Post a Comment

Thanks

Meta

Popular Posts

  • Write API Integrations in Laravel and PHP Projects with Saloon
    Write API Integrations in Laravel and PHP Projects with Saloon Saloon  is a Laravel/PHP package that allows you to write your API integratio...
  • Features CodeIgniter
    Features CodeIgniter There is a great demand for the CodeIgniter framework in PHP developers because of its features and multiple advan...
  • Laravel Breeze with PrimeVue v4
    This is an follow up to my previous post about a "starter kit" I created with Laravel and PrimeVue components. The project has b...
  • Fast Excel Package for Laravel
      Fast Excel is a Laravel package for importing and exporting spreadsheets. It provides an elegant wrapper around Spout —a PHP package to ...
  • Send message via CANBus
    After some years developing for mobile devices, I've started developing for embedded devices, and I'm finding a new problem now. Th...

Categories

  • Ajax (26)
  • Bootstrap (30)
  • DBMS (42)
  • HTML (12)
  • HTML5 (45)
  • JavaScript (10)
  • Jquery (34)
  • Jquery UI (2)
  • JqueryUI (32)
  • Laravel (1017)
  • Laravel Tutorials (23)
  • Laravel-Question (6)
  • Magento (9)
  • Magento 2 (95)
  • MariaDB (1)
  • MySql Tutorial (2)
  • PHP-Interview-Questions (3)
  • Php Question (13)
  • Python (36)
  • RDBMS (13)
  • SQL Tutorial (79)
  • Vue.js Tutorial (68)
  • Wordpress (150)
  • Wordpress Theme (3)
  • codeigniter (108)
  • oops (4)
  • php (853)

Social Media Links

  • Follow on Twitter
  • Like on Facebook
  • Subscribe on Youtube
  • Follow on Instagram

Pages

  • Home
  • Contact Us
  • Privacy Policy
  • About us

Blog Archive

  • September (100)
  • August (50)
  • July (56)
  • June (46)
  • May (59)
  • April (50)
  • March (60)
  • February (42)
  • January (53)
  • December (58)
  • November (61)
  • October (39)
  • September (36)
  • August (36)
  • July (34)
  • June (34)
  • May (36)
  • April (29)
  • March (82)
  • February (1)
  • January (8)
  • December (14)
  • November (41)
  • October (13)
  • September (5)
  • August (48)
  • July (9)
  • June (6)
  • May (119)
  • April (259)
  • March (122)
  • February (368)
  • January (33)
  • October (2)
  • July (11)
  • June (29)
  • May (25)
  • April (168)
  • March (93)
  • February (60)
  • January (28)
  • December (195)
  • November (24)
  • October (40)
  • September (55)
  • August (6)
  • July (48)
  • May (2)
  • January (2)
  • July (6)
  • June (6)
  • February (17)
  • January (69)
  • December (122)
  • November (56)
  • October (92)
  • September (76)
  • August (6)

Loading...

Laravel News

Loading...

Copyright © CoderFunda | Powered by Blogger
Design by Coderfunda | Blogger Theme by Coderfunda | Distributed By Coderfunda