Skip to content
Permalink
Browse files

Spinner: Return formatted value when using value method.

  • Loading branch information
scottgonzalez committed Aug 10, 2011
1 parent a0eb042 commit 7c7d3df8e7b90785a6725cb74863e793d21fea1a
Showing with 15 additions and 15 deletions.
  1. +15 −15 ui/jquery.ui.spinner.js
@@ -17,8 +17,7 @@ function modifier( fn ) {
return function() {
var previous = this.options.value;
fn.apply( this, arguments );
this._format();
this._aria();
this._refresh();
if ( previous !== this.options.value ) {
this._trigger( "change" );
}
@@ -48,7 +47,7 @@ $.widget( "ui.spinner", {
this._value( this.options.value );
this._draw();
this._mousewheel();
this._aria();
this._refresh();
},

_getCreateOptions: function() {
@@ -307,14 +306,6 @@ $.widget( "ui.spinner", {
this._value( this._trimValue( this.options.value ) );
}),

_aria: function() {
this.element.attr({
"aria-valuemin": this.options.min,
"aria-valuemax": this.options.max,
"aria-valuenow": this.options.value
});
},

_parse: function( val ) {
if ( typeof val === "string" ) {
val = $.global && this.options.numberFormat ? $.global.parseFloat( val ) : +val;
@@ -324,14 +315,23 @@ $.widget( "ui.spinner", {

_format: function() {
var num = this.options.value;
this.element.val( $.global && this.options.numberFormat ? $.global.format( num, this.options.numberFormat ) : num );
return $.global && this.options.numberFormat ? $.global.format( num, this.options.numberFormat ) : num;
},

_refresh: function() {
this.element
.val( this._format() )
.attr({
"aria-valuemin": this.options.min,
"aria-valuemax": this.options.max,
"aria-valuenow": this.options.value
});
},

// update the value without triggering change
_value: function( value ) {
this.options.value = this._trimValue( this._parse(value) );
this._format();
this._aria();
this._refresh();
},

destroy: function() {
@@ -371,7 +371,7 @@ $.widget( "ui.spinner", {

value: function( newVal ) {
if ( !arguments.length ) {
return this._parse( this.element.val() );
return this._format();
}
this.option( "value", newVal );
},

5 comments on commit 7c7d3df

@jzaefferer

This comment has been minimized.

Copy link
Member

jzaefferer replied Aug 10, 2011

Didn't the TODO on the wiki say the value option reflects the formatted value, the value method the raw one? I guess this matches the spec, but that needs to be updated, so provide consistent access to the raw value.

@jzaefferer

This comment has been minimized.

Copy link
Member

jzaefferer replied Aug 10, 2011

After some discussion with Corey on IRC I'm now wondering why spinner has a value option at all. We should have the value method to set and get the raw value, and just use .val() for setting and getting the formatted value. Mask and Autocomplete also don't have a value option and don't need it.

@scottgonzalez

This comment has been minimized.

Copy link
Member Author

scottgonzalez replied Aug 10, 2011

Umm...yes, I managed to somehow read the TODOs backward every single time I looked at them, several days in a row.

I believe the value option originally existed so we could differentiate between random values in the field and valid values. But as Corey points out, this is possible with .val() and a value method. Removing the value option sounds like a good idea. I'd keep the value method setter able to accept raw and formatted values, but the getter will always return raw.

@gnarf

This comment has been minimized.

Copy link
Member

gnarf replied Aug 10, 2011

That description meshes with the current implementation in Mask. .mask( "value", value ) can take a "raw" or a "formatted" value.

@jzaefferer

This comment has been minimized.

Copy link
Member

jzaefferer replied Aug 10, 2011

Okay, let's get that into the Spinner spec and impl.

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