]> source.dussan.org Git - jquery-ui.git/commitdiff
Spinner: Handle changes to numberFormat and currency options.
authorScott González <scott.gonzalez@gmail.com>
Wed, 16 Nov 2011 17:07:33 +0000 (12:07 -0500)
committerScott González <scott.gonzalez@gmail.com>
Wed, 16 Nov 2011 17:07:46 +0000 (12:07 -0500)
demos/spinner/currency.html
tests/unit/spinner/spinner_options.js
ui/jquery.ui.spinner.js

index 485ad90647ee7f9d8813ab69bb9adcbfb140ce19..796b379a53a4c53284477588d91ebf3f4adaab87 100644 (file)
@@ -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({
index d954c8b9a2efc52d4fde7d47c0bcdbc8ceb3729e..81f434fc6e4d1581448ddf0ecb601d0fc3fe2b0c 100644 (file)
@@ -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 });
index 9c554b2dfe9880c7d3e35b791fc42a3d6b4fcbec..5623722db271b2a6b4354abb022660f3c8da97e9 100644 (file)
@@ -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" ) {