diff options
author | Scott González <scott.gonzalez@gmail.com> | 2011-11-16 12:07:33 -0500 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2011-11-16 12:07:46 -0500 |
commit | 924e80e576e098fd07899bc6e2d5929680d54446 (patch) | |
tree | 92b9a20255df56ad997e41ace4817705cc7d2324 | |
parent | 97bc2d9de9875e222254cfa1cd3fa3bde605c2ed (diff) | |
download | jquery-ui-924e80e576e098fd07899bc6e2d5929680d54446.tar.gz jquery-ui-924e80e576e098fd07899bc6e2d5929680d54446.zip |
Spinner: Handle changes to numberFormat and currency options.
-rw-r--r-- | demos/spinner/currency.html | 4 | ||||
-rw-r--r-- | tests/unit/spinner/spinner_options.js | 19 | ||||
-rw-r--r-- | ui/jquery.ui.spinner.js | 7 |
3 files changed, 27 insertions, 3 deletions
diff --git a/demos/spinner/currency.html b/demos/spinner/currency.html index 485ad9064..796b379a5 100644 --- a/demos/spinner/currency.html +++ b/demos/spinner/currency.html @@ -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({ diff --git a/tests/unit/spinner/spinner_options.js b/tests/unit/spinner/spinner_options.js index d954c8b9a..81f434fc6 100644 --- a/tests/unit/spinner/spinner_options.js +++ b/tests/unit/spinner/spinner_options.js @@ -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 }); diff --git a/ui/jquery.ui.spinner.js b/ui/jquery.ui.spinner.js index 9c554b2df..5623722db 100644 --- a/ui/jquery.ui.spinner.js +++ b/ui/jquery.ui.spinner.js @@ -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" ) { |