]> source.dussan.org Git - jquery-ui.git/commitdiff
Calendar: Clear value if an invalid input was given
authorFelix Nagel <info@felixnagel.com>
Wed, 12 Oct 2016 09:36:48 +0000 (11:36 +0200)
committerFelix Nagel <info@felixnagel.com>
Wed, 12 Oct 2016 16:47:22 +0000 (18:47 +0200)
tests/unit/calendar/methods.js
tests/unit/calendar/options.js
ui/widgets/calendar.js

index c27e80303fc16992711b0cd8d97162b3e6b764f0..964d6c18684d6ef3a2d2a8a7ea05b3101b3ba013 100644 (file)
@@ -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 );
index bd87edb6c49637fafaab81678d926d7a7c589781..c5bbdbf5ab7fccfbb5f7d6652f516c576a70b61e 100644 (file)
@@ -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" );
 } );
 
 /*
index ba45c1c847bd91ae2057d393fc4432a372e581fe..006332d1bd77d937d9139ab16c2d824fda9879e5 100644 (file)
@@ -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" ) {