Spinner: Added culture option.

This commit is contained in:
Scott González
2011-09-28 18:30:58 -04:00
parent 39b452e1be
commit c2f036277c
4 changed files with 31 additions and 2 deletions

View File

@@ -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>

View File

@@ -1,5 +1,6 @@
commonWidgetTests( "spinner", {
defaults: {
culture: null,
disabled: false,
incremental: true,
max: null,

View File

@@ -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 });

View File

@@ -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;
},