Using moment.js formatting with a Nullable Datetime

Using moment.js formatting with a Nullable Datetime

pcjacksonpcjackson Posts: 18Questions: 6Answers: 0

When defining a column as:

{
  "label": "Expiration Date",
  "name": "items.Shelf_life_exp",
  "type": "datetime",
  "displayFormat": "ddd DD MMM, YYYY",
  "wireFormat": "YYYY-MM-DD",
  "opts": {
    "momentLocale": "en",
    "momentStrict": true
  }
}

where items.Shelf_life_exp is a nullable datetime in the database (and passed a string in the model), I get null across the wire when this field is not set. This results in a null being passed to moment and being emitted as "Invalid Date." And "Invalid Date" fails to save in the database on the other end.

.Field(new Field("items.Shelf_life_exp")
    .GetFormatter(Format.DateSqlToFormat(Format.DATE_ISO_8601))
    .SetFormatter(Format.DateFormatToSql(Format.DATE_ISO_8601)))

Is there a way to either:

a) instruct moment.js to emit empty string or similar when fed a null date
b) instruct editor to not pass null date to moment.js
c) allow the server to accept "Invalid Date" or any other invalidly formatted date as a null date?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,195Questions: 1Answers: 10,412 Site admin

    Option a) is going to be the correct one here, but I think it will also need a little update to the DateFormatToSql function to return null on an empty string. Let me look into this and get back to you.

    Allan

  • pcjacksonpcjackson Posts: 18Questions: 6Answers: 0
    edited November 2019

    In another thread you mentioned this was (probably) going to land in 1.9.3.

    Do you have an approximate ETA on that patch? (Days? Weeks? Months?)

  • allanallan Posts: 63,195Questions: 1Answers: 10,412 Site admin
    Answer ✓

    I don't yet I'm afraid. I would hope to drop the patch release before the end of the month though.

    Allan

This discussion has been closed.