mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Calendar: Clear value if an invalid input was given
This commit is contained in:
parent
f64a7a4812
commit
bd488f97a4
@ -56,7 +56,7 @@ test( "value", function( assert ) {
|
||||
equal( this.element.calendar( "value" ), "1/1/14", "getter" );
|
||||
|
||||
this.element.calendar( "value", "abc" );
|
||||
equal( this.element.calendar( "value" ), "1/1/14", "Setting invalid values should be ignored." );
|
||||
equal( this.element.calendar( "value" ), null, "Setting invalid values." );
|
||||
} );
|
||||
|
||||
test( "valueAsDate", function( assert ) {
|
||||
@ -95,9 +95,9 @@ test( "valueAsDate", function( assert ) {
|
||||
);
|
||||
|
||||
this.element.calendar( "valueAsDate", date1 );
|
||||
assert.dateEqual(
|
||||
equal(
|
||||
this.element.calendar( "valueAsDate" ),
|
||||
date2,
|
||||
null,
|
||||
"Set date min/max - value < min"
|
||||
);
|
||||
|
||||
@ -111,25 +111,25 @@ test( "valueAsDate", function( assert ) {
|
||||
);
|
||||
|
||||
this.element.calendar( "valueAsDate", date2 );
|
||||
assert.dateEqual(
|
||||
equal(
|
||||
this.element.calendar( "valueAsDate" ),
|
||||
date1,
|
||||
null,
|
||||
"Set date min/max - value > max"
|
||||
);
|
||||
|
||||
this.element
|
||||
.calendar( "option", { min: minDate } )
|
||||
.calendar( "valueAsDate", date1 );
|
||||
assert.dateEqual(
|
||||
equal(
|
||||
this.element.calendar( "valueAsDate" ),
|
||||
date1,
|
||||
null,
|
||||
"Set date min/max - value < min"
|
||||
);
|
||||
|
||||
this.element.calendar( "valueAsDate", date2 );
|
||||
assert.dateEqual(
|
||||
equal(
|
||||
this.element.calendar( "valueAsDate" ),
|
||||
date1, "Set date min/max - value > max"
|
||||
null, "Set date min/max - value > max"
|
||||
);
|
||||
|
||||
dateAndTimeToSet = new Date( 2008, 3 - 1, 28, 1, 11, 0 );
|
||||
|
@ -203,7 +203,7 @@ test( "min / max", function( assert ) {
|
||||
this.element
|
||||
.calendar( "option", { min: minDate } )
|
||||
.calendar( "value", "1/4/08" );
|
||||
assert.dateEqual( this.element.calendar( "valueAsDate" ), new Date( 2008, 6 - 1, 4 ), "Min/max - value < min" );
|
||||
equal( this.element.calendar( "valueAsDate" ), null, "Min/max - value < min" );
|
||||
|
||||
this.element
|
||||
.calendar( "option", { min: null } )
|
||||
@ -214,12 +214,12 @@ test( "min / max", function( assert ) {
|
||||
this.element
|
||||
.calendar( "option", { max: maxDate } )
|
||||
.calendar( "value", "1/4/09" );
|
||||
assert.dateEqual( this.element.calendar( "valueAsDate" ), new Date( 2008, 6 - 1, 4 ), "Min/max - setDate > max" );
|
||||
equal( this.element.calendar( "valueAsDate" ), null, "Min/max - setDate > max" );
|
||||
|
||||
this.element
|
||||
.calendar( "option", { min: minDate, max: maxDate } )
|
||||
.calendar( "value", "1/4/08" );
|
||||
assert.dateEqual( this.element.calendar( "valueAsDate" ), new Date( 2008, 6 - 1, 4 ), "Min/max - value < min" );
|
||||
equal( this.element.calendar( "valueAsDate" ), null, "Min/max - value < min" );
|
||||
|
||||
this.element
|
||||
.calendar( "option", { min: minDate, max: maxDate } )
|
||||
@ -229,7 +229,7 @@ test( "min / max", function( assert ) {
|
||||
this.element
|
||||
.calendar( "option", { min: minDate, max: maxDate } )
|
||||
.calendar( "value", "1/4/09" );
|
||||
assert.dateEqual( this.element.calendar( "valueAsDate" ), new Date( 2008, 6 - 1, 4 ), "Min/max - value > max" );
|
||||
equal( this.element.calendar( "valueAsDate" ), null, "Min/max - value > max" );
|
||||
|
||||
this.element
|
||||
.calendar( "option", { min: minDate, max: maxDate } )
|
||||
@ -326,7 +326,7 @@ test( "value", function( assert ) {
|
||||
);
|
||||
|
||||
this.element.calendar( "option", "value", "invalid" );
|
||||
assert.dateEqual( this.element.calendar( "option", "value" ), date, "Value after invalid parameter" );
|
||||
equal( this.element.calendar( "option", "value" ), null, "Value after invalid parameter" );
|
||||
} );
|
||||
|
||||
/*
|
||||
|
@ -646,7 +646,8 @@ return $.widget( "ui.calendar", {
|
||||
if ( arguments.length ) {
|
||||
this.valueAsDate( this._parse( value ) );
|
||||
} else {
|
||||
return this._format( this.option( "value" ) );
|
||||
return this.option( "value" ) === null ?
|
||||
null : this._format( this.option( "value" ) );
|
||||
}
|
||||
},
|
||||
|
||||
@ -716,9 +717,9 @@ return $.widget( "ui.calendar", {
|
||||
if ( key === "value" ) {
|
||||
if ( this._isValid( value ) ) {
|
||||
this.date.setTime( value.getTime() );
|
||||
this._super( key, value );
|
||||
} else {
|
||||
value = null;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if ( key === "max" || key === "min" ) {
|
||||
|
Loading…
Reference in New Issue
Block a user