From: Felix Nagel Date: Wed, 12 Oct 2016 09:36:48 +0000 (+0200) Subject: Calendar: Clear value if an invalid input was given X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=bd488f97a434ca54c0e57104ab85d2703444364b;p=jquery-ui.git Calendar: Clear value if an invalid input was given --- diff --git a/tests/unit/calendar/methods.js b/tests/unit/calendar/methods.js index c27e80303..964d6c186 100644 --- a/tests/unit/calendar/methods.js +++ b/tests/unit/calendar/methods.js @@ -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 ); diff --git a/tests/unit/calendar/options.js b/tests/unit/calendar/options.js index bd87edb6c..c5bbdbf5a 100644 --- a/tests/unit/calendar/options.js +++ b/tests/unit/calendar/options.js @@ -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" ); } ); /* diff --git a/ui/widgets/calendar.js b/ui/widgets/calendar.js index ba45c1c84..006332d1b 100644 --- a/ui/widgets/calendar.js +++ b/ui/widgets/calendar.js @@ -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" ) {