Skip to content

Commit c2f0362

Browse files
committed
Spinner: Added culture option.
1 parent 39b452e commit c2f0362

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

tests/unit/spinner/spinner.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<script src="../../jquery.js"></script>
1010
<script src="../../../external/jquery.mousewheel-3.0.4.js"></script>
1111
<script src="../../../external/globalize.js"></script>
12+
<script src="../../../external/globalize.culture.ja-JP.js"></script>
1213
<script src="../../../ui/jquery.ui.core.js"></script>
1314
<script src="../../../ui/jquery.ui.widget.js"></script>
1415
<script src="../../../ui/jquery.ui.button.js"></script>

tests/unit/spinner/spinner_defaults.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
commonWidgetTests( "spinner", {
22
defaults: {
3+
culture: null,
34
disabled: false,
45
incremental: true,
56
max: null,

tests/unit/spinner/spinner_options.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
module( "spinner: options" );
44

5+
// culture is tested after numberFormat, since it depends on numberFormat
6+
57
test( "incremental, false", function() {
68
expect( 100 );
79

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

96+
test( "culture, null", function() {
97+
expect( 2 );
98+
Globalize.culture( "ja-JP" );
99+
var element = $( "#spin" ).val( 0 ).spinner({ numberFormat: "C" });
100+
equal( element.val(), "¥0", "formatted on init" );
101+
element.spinner( "stepUp" );
102+
equal( element.val(), "¥1", "formatted after step" );
103+
104+
// reset culture
105+
Globalize.culture( "default" );
106+
});
107+
108+
test( "currency, ja-JP", function() {
109+
expect( 2 );
110+
var element = $( "#spin" ).val( 0 ).spinner({
111+
numberFormat: "C",
112+
culture: "ja-JP"
113+
});
114+
equal( element.val(), "¥0", "formatted on init" );
115+
element.spinner( "stepUp" );
116+
equal( element.val(), "¥1", "formatted after step" );
117+
});
118+
94119
test( "max", function() {
95120
expect( 3 );
96121
var element = $( "#spin" ).val( 1000 ).spinner({ max: 100 });

ui/jquery.ui.spinner.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ $.widget( "ui.spinner", {
3030
defaultElement: "<input>",
3131
widgetEventPrefix: "spin",
3232
options: {
33+
culture: null,
3334
incremental: true,
3435
max: null,
3536
min: null,
@@ -320,7 +321,8 @@ $.widget( "ui.spinner", {
320321

321322
_parse: function( val ) {
322323
if ( typeof val === "string" && val !== "" ) {
323-
val = window.Globalize && this.options.numberFormat ? Globalize.parseFloat( val ) : +val;
324+
val = window.Globalize && this.options.numberFormat ?
325+
Globalize.parseFloat( val, 10, this.options.culture ) : +val;
324326
}
325327
return val === "" || isNaN( val ) ? null : val;
326328
},
@@ -330,7 +332,7 @@ $.widget( "ui.spinner", {
330332
return "";
331333
}
332334
return window.Globalize && this.options.numberFormat ?
333-
Globalize.format( value, this.options.numberFormat ) :
335+
Globalize.format( value, this.options.numberFormat, this.options.culture ) :
334336
value;
335337
},
336338

0 commit comments

Comments
 (0)