gcanti / tcomb-validation

Validation library based on type combinators
MIT License
400 stars 23 forks source link

InvalidDate is not detected as invalid #31

Closed pgmemk closed 9 years ago

pgmemk commented 9 years ago

When DatePicker is displayed the value for it set to current date. If the value was not changed before submit the value that comes with the form is InvalidDate

In index.js in tcomb-validation there is

validators.enums = function validateIrreducible(x, type, path) {
    return {
      value: x,
      errors: type.is(x) ? [] : [ValidationError.of(x, type, path)]
    };
  };

type.is(x) returns true in case of InvalidDate that is why no error was detected. Probably there is a need to check something like this:

if (Object.prototype.toString.call(x) === '[object Date]'  &&  isNaN(v.getTime())))
  // create an error

or set the value for the date field to current date

Could you please take a look?

gcanti commented 9 years ago

When DatePicker is displayed...

You are speaking of tcomb-form-native I guess. Could you please reopen this issue there, with a simple example reproducing the problem?