Skip to content
Permalink
Browse files

Spinner: Handle changes to numberFormat and currency options.

  • Loading branch information...
scottgonzalez committed Nov 16, 2011
1 parent 97bc2d9 commit 924e80e576e098fd07899bc6e2d5929680d54446
Showing with 27 additions and 3 deletions.
  1. +1 −3 demos/spinner/currency.html
  2. +19 −0 tests/unit/spinner/spinner_options.js
  3. +7 −0 ui/jquery.ui.spinner.js
@@ -17,9 +17,7 @@
<script>
$(function() {
$( "#currency" ).change(function() {
var current = $( "#spinner" ).spinner( "value" );
Globalize.culture( $(this).val() );
$( "#spinner" ).spinner( "value", current );
$( "#spinner" ).spinner( "option", "culture", $( this ).val() );
});
$( "#spinner" ).spinner({
@@ -96,6 +96,14 @@ test( "numberFormat, currency", function() {
equal( element.val(), "$1.00", "formatted after step" );
});

test( "numberFormat, change", function() {
expect( 2 );
var element = $( "#spin" ).val( 5 ).spinner({ numberFormat: "n1" });
equal( element.val(), "5.0", "formatted on init" );
element.spinner( "option", "numberFormat", "c" );
equal( element.val(), "$5.00", "formatted after change" );
});

test( "culture, null", function() {
expect( 2 );
Globalize.culture( "ja-JP" );
@@ -119,6 +127,17 @@ test( "currency, ja-JP", function() {
equal( element.val(), "¥1", "formatted after step" );
});

test( "currency, change", function() {
expect( 2 );
var element = $( "#spin" ).val( 5 ).spinner({
numberFormat: "C",
culture: "ja-JP"
});
equal( element.val(), "¥5", "formatted on init" );
element.spinner( "option", "culture", "en" );
equal( element.val(), "$5.00", "formatted after change" );
});

test( "max", function() {
expect( 3 );
var element = $( "#spin" ).val( 1000 ).spinner({ max: 100 });
@@ -311,6 +311,13 @@ $.widget( "ui.spinner", {
},

_setOption: function( key, value ) {
if ( key === "culture" || key === "numberFormat" ) {
var prevValue = this._parse( this.element.val() );
this.options[ key ] = value;
this.element.val( this._format( prevValue ) );
return;
}

this._super( "_setOption", key, value );

if ( key === "disabled" ) {

0 comments on commit 924e80e

Please sign in to comment.
You can’t perform that action at this time.