Using DateField in Form

Hi.

I changed a field in schema.prisma from String to DateTime, ran yarn db save bar and yarn rw db up. Then I changed the tag in the form from TextField to DateField and I get a date-selector which is a nice touch. :slight_smile:

When the input-field in the form is empty it displays dd.mm.åååå that indicates it is expecting a date (day, month, year). The field is not mandatory so it can be empty.

When I try to update with an empty value I get the error

An error has occurred
* Expected type Date. Date cannot represent an invalid date-string .

I found out it is trying to save an empty value (string?) with length 0 and this is not a correct date. So what I did was to add this check before saving, in my case the file EditEnhetCell.js:

if (input.foo.length == 0) {
  input.foo = null
}

and I can make changes to other fields in a record and save it.

Regards
Claus

1 Like

Thanks for the report! We’re working on a way to automatically check type and set empty fields back to null for you automatically, but for now you have to do it manually. Sorry about that!

We’ve got a couple outstanding discussions/issues about this:

1 Like

Thank you for the fast response. :slight_smile: And pardon I did not search for existing tickets.

I’m glad redwoodjs is quite an opinionated framework so I can find my way around in the structure and make the necessary changes.

1 Like