From b4fe65a1347ebeb47d6deb05e5c49d76be01bb0b Mon Sep 17 00:00:00 2001 From: TJ VanToll Date: Fri, 3 Jan 2014 09:07:38 -0500 Subject: [PATCH] Datepicker: Add an `isValid()` method --- tests/unit/datepicker/datepicker_methods.js | 13 +++++++++++++ ui/datepicker.js | 3 +++ 2 files changed, 16 insertions(+) diff --git a/tests/unit/datepicker/datepicker_methods.js b/tests/unit/datepicker/datepicker_methods.js index 81d1b096b..98034dacd 100644 --- a/tests/unit/datepicker/datepicker_methods.js +++ b/tests/unit/datepicker/datepicker_methods.js @@ -111,4 +111,17 @@ test( "valueAsDate", function() { inline.datepicker( "destroy" ); }); +test( "isValid", function() { + expect( 2 ); + var input = $( "#datepicker" ).datepicker(); + + input.val( "1/1/14" ); + ok( input.datepicker( "isValid" ) ); + + input.val( "1/1/abc" ); + ok( !input.datepicker( "isValid" ) ); + + input.datepicker( "destroy" ); +}); + })( jQuery ); diff --git a/ui/datepicker.js b/ui/datepicker.js index 43f640e4e..9f0e1905e 100644 --- a/ui/datepicker.js +++ b/ui/datepicker.js @@ -654,6 +654,9 @@ $.widget( "ui.datepicker", { return this.date.date(); } }, + isValid: function() { + return Globalize.parseDate( this.element.val(), this.options.dateFormat ) !== null; + }, _destroy: function() { if ( this.inline ) { this.picker.empty();