Skip to content

Commit de4e863

Browse files
committed
Merge branch 'selectmenu' of github.com:jquery/jquery-ui into selectmenu
2 parents 4ddd14f + 134fcaf commit de4e863

File tree

5 files changed

+67
-5
lines changed

5 files changed

+67
-5
lines changed

AUTHORS.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ Anika Henke <anika@selfthinker.org>
226226
Samuel Bovée <samycookie2000@yahoo.fr>
227227
Fabrício Matté <ult_combo@hotmail.com>
228228
Viktor Kojouharov <vkojouharov@gmail.com>
229-
Pawel Maruszczyk <lord_t@o2.pl>
229+
Pawel Maruszczyk (http://hrabstwo.net)
230230
Pavel Selitskas <p.selitskas@gmail.com>
231231
Bjørn Johansen <bjorn.johansen@metronet.no>
232232
Matthieu Penant <thieum22@hotmail.com>

tests/unit/spinner/spinner_methods.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,38 @@ test( "enable", function() {
7373
equal( 2, element.val(), "keyboard - value changes on key UP" );
7474
});
7575

76+
test( "isValid", function() {
77+
expect( 8 );
78+
var element = $( "#spin" ).spinner({
79+
min: 0,
80+
max: 10,
81+
step: 2
82+
}),
83+
spinner = element.spinner( "instance" );
84+
ok( !spinner.isValid(), "initial state is invalid" );
85+
86+
element.val( "this is not a number" );
87+
ok( !spinner.isValid(), "text string is not valid" );
88+
89+
element.val( "0" );
90+
ok( spinner.isValid(), "min value is valid" );
91+
92+
element.val( "10" );
93+
ok( spinner.isValid(), "max value is valid" );
94+
95+
element.val( "4" );
96+
ok( spinner.isValid(), "inbetween step is valid" );
97+
98+
element.val( "-1" );
99+
ok( !spinner.isValid(), "below min is invalid" );
100+
101+
element.val( "11" );
102+
ok( !spinner.isValid(), "above max is invalid" );
103+
104+
element.val( "1" );
105+
ok( !spinner.isValid(), "step mismatch is invalid" );
106+
});
107+
76108
test( "pageDown", function() {
77109
expect( 4 );
78110
var element = $( "#spin" ).val( -12 ).spinner({

tests/unit/widget/widget_core.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,7 @@ asyncTest( "_delay", function() {
14091409
});
14101410

14111411
test( "$.widget.bridge()", function() {
1412-
expect( 10 );
1412+
expect( 14 );
14131413

14141414
var instance, ret,
14151415
elem = $( "<div>" );
@@ -1427,6 +1427,9 @@ test( "$.widget.bridge()", function() {
14271427
},
14281428
getter: function() {
14291429
return "qux";
1430+
},
1431+
option: function( options ) {
1432+
deepEqual( options, {} );
14301433
}
14311434
});
14321435

@@ -1444,6 +1447,14 @@ test( "$.widget.bridge()", function() {
14441447

14451448
ret = elem.testWidget( "getter" );
14461449
equal( ret, "qux", "getter returns value" );
1450+
1451+
elem.testWidget();
1452+
ok( true, "_init is optional" );
1453+
1454+
TestWidget.prototype._init = function() {
1455+
ok( "_init", "_init now exists, so its called" );
1456+
};
1457+
elem.testWidget();
14471458
});
14481459

14491460
test( "$.widget.bridge() - widgetFullName", function() {

ui/jquery.ui.spinner.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,18 @@ $.widget( "ui.spinner", {
418418
});
419419
},
420420

421+
isValid: function() {
422+
var value = this.value();
423+
424+
// null is invalid
425+
if ( value === null ) {
426+
return false;
427+
}
428+
429+
// if value gets adjusted, it's invalid
430+
return value === this._adjustValue( value );
431+
},
432+
421433
// update the value without triggering change
422434
_value: function( value, allowAny ) {
423435
var parsed;

ui/jquery.ui.widget.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,10 @@ $.widget.bridge = function( name, object ) {
203203
this.each(function() {
204204
var instance = $.data( this, fullName );
205205
if ( instance ) {
206-
instance.option( options || {} )._init();
206+
instance.option( options || {} );
207+
if ( instance._init ) {
208+
instance._init();
209+
}
207210
} else {
208211
$.data( this, fullName, new object( options, this ) );
209212
}
@@ -349,8 +352,12 @@ $.Widget.prototype = {
349352
if ( key === "disabled" ) {
350353
this.widget()
351354
.toggleClass( this.widgetFullName + "-disabled", !!value );
352-
this.hoverable.removeClass( "ui-state-hover" );
353-
this.focusable.removeClass( "ui-state-focus" );
355+
356+
// If the widget is becoming disabled, then nothing is interactive
357+
if ( value ) {
358+
this.hoverable.removeClass( "ui-state-hover" );
359+
this.focusable.removeClass( "ui-state-focus" );
360+
}
354361
}
355362

356363
return this;

0 commit comments

Comments
 (0)