Skip to content
Permalink
Browse files

Spinner: Added culture option.

  • Loading branch information
scottgonzalez committed Sep 28, 2011
1 parent 39b452e commit c2f036277c6190bc8677bc0eac53c22ed5e8a08d
@@ -9,6 +9,7 @@
<script src="../../jquery.js"></script>
<script src="../../../external/jquery.mousewheel-3.0.4.js"></script>
<script src="../../../external/globalize.js"></script>
<script src="../../../external/globalize.culture.ja-JP.js"></script>
<script src="../../../ui/jquery.ui.core.js"></script>
<script src="../../../ui/jquery.ui.widget.js"></script>
<script src="../../../ui/jquery.ui.button.js"></script>
@@ -1,5 +1,6 @@
commonWidgetTests( "spinner", {
defaults: {
culture: null,
disabled: false,
incremental: true,
max: null,
@@ -2,6 +2,8 @@

module( "spinner: options" );

// culture is tested after numberFormat, since it depends on numberFormat

test( "incremental, false", function() {
expect( 100 );

@@ -91,6 +93,29 @@ test( "numberFormat, currency", function() {
equal( element.val(), "$1.00", "formatted after step" );
});

test( "culture, null", function() {
expect( 2 );
Globalize.culture( "ja-JP" );
var element = $( "#spin" ).val( 0 ).spinner({ numberFormat: "C" });
equal( element.val(), "¥0", "formatted on init" );
element.spinner( "stepUp" );
equal( element.val(), "¥1", "formatted after step" );

// reset culture
Globalize.culture( "default" );
});

test( "currency, ja-JP", function() {
expect( 2 );
var element = $( "#spin" ).val( 0 ).spinner({
numberFormat: "C",
culture: "ja-JP"
});
equal( element.val(), "¥0", "formatted on init" );
element.spinner( "stepUp" );
equal( element.val(), "¥1", "formatted after step" );
});

test( "max", function() {
expect( 3 );
var element = $( "#spin" ).val( 1000 ).spinner({ max: 100 });
@@ -30,6 +30,7 @@ $.widget( "ui.spinner", {
defaultElement: "<input>",
widgetEventPrefix: "spin",
options: {
culture: null,
incremental: true,
max: null,
min: null,
@@ -320,7 +321,8 @@ $.widget( "ui.spinner", {

_parse: function( val ) {
if ( typeof val === "string" && val !== "" ) {
val = window.Globalize && this.options.numberFormat ? Globalize.parseFloat( val ) : +val;
val = window.Globalize && this.options.numberFormat ?
Globalize.parseFloat( val, 10, this.options.culture ) : +val;
}
return val === "" || isNaN( val ) ? null : val;
},
@@ -330,7 +332,7 @@ $.widget( "ui.spinner", {
return "";
}
return window.Globalize && this.options.numberFormat ?
Globalize.format( value, this.options.numberFormat ) :
Globalize.format( value, this.options.numberFormat, this.options.culture ) :
value;
},

0 comments on commit c2f0362

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