equals( element.val(), 1000, "value not constrained on init" );
element.spinner( "value", 1000 );
- equals( element.val(), 100, "max constrained if value method is greater" );
+ equals( element.val(), 100, "max constrained in value method" );
element.val( 1000 ).blur();
equals( element.val(), 1000, "max not constrained if manual entry" );
});
+test( "max, string", function() {
+ expect( 3 );
+ var element = $( "#spin" )
+ .val( 1000 )
+ .spinner({
+ max: "$100.00",
+ numberFormat: "C",
+ culture: "en"
+ });
+ equals( element.val(), "$1,000.00", "value not constrained on init" );
+ equals( element.spinner( "option", "max" ), 100, "option converted to number" );
+
+ element.spinner( "value", 1000 );
+ equals( element.val(), "$100.00", "max constrained in value method" );
+});
+
test( "min", function() {
expect( 3 );
var element = $( "#spin" ).val( -1000 ).spinner({ min: -100 });
equals( element.val(), -1000, "value not constrained on init" );
element.spinner( "value", -1000 );
- equals( element.val(), -100, "min constrained if value method is greater" );
+ equals( element.val(), -100, "min constrained in value method" );
element.val( -1000 ).blur();
equals( element.val(), -1000, "min not constrained if manual entry" );
});
+test( "min, string", function() {
+ expect( 3 );
+ var element = $( "#spin" )
+ .val( -1000 )
+ .spinner({
+ min: "-$100.00",
+ numberFormat: "C",
+ culture: "en"
+ });
+ equals( element.val(), "($1,000.00)", "value not constrained on init" );
+ equals( element.spinner( "option", "min" ), -100, "option converted to number" );
+
+ element.spinner( "value", -1000 );
+ equals( element.val(), "($100.00)", "min constrained in value method")
+});
+
test( "step, 2", function() {
expect( 3 );
var element = $( "#spin" ).val( 0 ).spinner({ step: 2 });
equals( element.val(), "0.7", "stepUp" );
});
+test( "step, string", function() {
+ expect( 2 );
+ var element = $("#spin").val( 0 ).spinner({
+ step: "$0.70",
+ numberFormat: "C",
+ culture: "en"
+ });
+
+ equals( element.spinner( "option", "step" ), 0.7, "option converted to number" );
+
+ element.spinner( "stepUp" );
+ equals( element.val(), "$0.70", "stepUp" );
+});
+
})( jQuery );
},
_create: function() {
+ // handle string values that need to be parsed
+ this._setOption( "max", this.options.max );
+ this._setOption( "min", this.options.min );
+ this._setOption( "step", this.options.step );
+
+ // format the value, but don't constrain
this._value( this.element.val(), true );
+
this._draw();
this._bind( this._events );
this._refresh();
return;
}
+ if ( key === "max" || key === "min" || key === "step" ) {
+ if ( typeof value === "string" ) {
+ value = this._parse( value );
+ }
+ }
+
this._super( key, value );
if ( key === "disabled" ) {