Datepicker: Add an isValid() method

This commit is contained in:
TJ VanToll 2014-01-03 09:07:38 -05:00 committed by Scott González
parent 104f3e6be0
commit b4fe65a134
2 changed files with 16 additions and 0 deletions

View File

@ -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 );

View File

@ -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();