Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
Merge branch 'master' into greenkeeper-serve-static-1.12.2
Browse files Browse the repository at this point in the history
  • Loading branch information
swilliamset authored May 3, 2017
2 parents 26cbb9a + d025932 commit f50613a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
18 changes: 13 additions & 5 deletions js/spinbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@
},

render: function render() {
this.setValue(this.getDisplayValue());
this._setValue(this.getDisplayValue());
},

change: function change() {
this.setValue(this.getDisplayValue());
this._setValue(this.getDisplayValue());

this.triggerChangedEvent();
},
Expand Down Expand Up @@ -222,7 +222,7 @@

step: function step(isIncrease) {
//refresh value from display before trying to increment in case they have just been typing before clicking the nubbins
this.setValue(this.getDisplayValue());
this._setValue(this.getDisplayValue());
var newVal;

if (isIncrease) {
Expand All @@ -233,7 +233,7 @@

newVal = newVal.toFixed(5);

this.setValue(newVal + this.unit);
this._setValue(newVal + this.unit);
},

getDisplayValue: function getDisplayValue() {
Expand All @@ -255,6 +255,10 @@
},

setValue: function setValue(val) {
return this._setValue(val, true);
},

_setValue: function _setValue(val, shouldSetLastValue) {
//remove any i18n on the number
if (this.options.decimalMark !== '.') {
val = this.parseInput(val);
Expand All @@ -271,7 +275,7 @@

//make sure we are dealing with a number
if (isNaN(intVal) && !isFinite(intVal)) {
return this.setValue(this.options.value);
return this._setValue(this.options.value, shouldSetLastValue);
}

//conform
Expand All @@ -290,6 +294,10 @@
//display number
this.setDisplayValue(val);

if (shouldSetLastValue) {
this.lastValue = val;
}

return this;
},

Expand Down
15 changes: 15 additions & 0 deletions test/spinbox-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,21 @@ define( function ( require ) {

} );

QUnit.test('spinbox should trigger change after using setValue', function (assert) {
var $spinbox = $(html).find('#MySpinboxDecimal').spinbox({
value: '1'
});

$spinbox.spinbox('setValue', '2');

$spinbox.on('changed.fu.spinbox', function () {
assert.ok(true, 'spinbox triggers changed after input' );
});

$spinbox.find('.spinbox-input').val(1);
$spinbox.find('.spinbox-input').focusout();
});

QUnit.test( "should destroy control", function( assert ) {
var $el = $( html ).find( "#MySpinbox" );

Expand Down

0 comments on commit f50613a

Please sign in to comment.