mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Spinner: Add isValid method. Fixes #9542 - Spinner: Add isValid() method
This commit is contained in:
parent
6e799c39d3
commit
1552fc8a05
@ -73,6 +73,38 @@ test( "enable", function() {
|
||||
equal( 2, element.val(), "keyboard - value changes on key UP" );
|
||||
});
|
||||
|
||||
test( "isValid", function() {
|
||||
expect( 8 );
|
||||
var element = $( "#spin" ).spinner({
|
||||
min: 0,
|
||||
max: 10,
|
||||
step: 2
|
||||
}),
|
||||
spinner = element.spinner( "instance" );
|
||||
ok( !spinner.isValid(), "initial state is invalid" );
|
||||
|
||||
element.val( "this is not a number" );
|
||||
ok( !spinner.isValid(), "text string is not valid" );
|
||||
|
||||
element.val( "0" );
|
||||
ok( spinner.isValid(), "min value is valid" );
|
||||
|
||||
element.val( "10" );
|
||||
ok( spinner.isValid(), "max value is valid" );
|
||||
|
||||
element.val( "4" );
|
||||
ok( spinner.isValid(), "inbetween step is valid" );
|
||||
|
||||
element.val( "-1" );
|
||||
ok( !spinner.isValid(), "below min is invalid" );
|
||||
|
||||
element.val( "11" );
|
||||
ok( !spinner.isValid(), "above max is invalid" );
|
||||
|
||||
element.val( "1" );
|
||||
ok( !spinner.isValid(), "step mismatch is invalid" );
|
||||
});
|
||||
|
||||
test( "pageDown", function() {
|
||||
expect( 4 );
|
||||
var element = $( "#spin" ).val( -12 ).spinner({
|
||||
|
12
ui/jquery.ui.spinner.js
vendored
12
ui/jquery.ui.spinner.js
vendored
@ -418,6 +418,18 @@ $.widget( "ui.spinner", {
|
||||
});
|
||||
},
|
||||
|
||||
isValid: function() {
|
||||
var value = this.value();
|
||||
|
||||
// null is invalid
|
||||
if ( value === null ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// if value gets adjusted, it's invalid
|
||||
return value === this._adjustValue( value );
|
||||
},
|
||||
|
||||
// update the value without triggering change
|
||||
_value: function( value, allowAny ) {
|
||||
var parsed;
|
||||
|
Loading…
Reference in New Issue
Block a user