mirror of
https://github.com/jquery/jquery-ui.git
synced 2025-01-07 20:34:24 +00:00
Spinner: Handle changes to numberFormat and currency options.
This commit is contained in:
parent
97bc2d9de9
commit
924e80e576
@ -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({
|
||||
|
@ -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 });
|
||||
|
7
ui/jquery.ui.spinner.js
vendored
7
ui/jquery.ui.spinner.js
vendored
@ -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" ) {
|
||||
|
Loading…
Reference in New Issue
Block a user