vascofg / react-admin-date-inputs

Date Inputs for react-admin
MIT License
68 stars 78 forks source link

getStartOfMonth is not a function error #26

Open bawpcwpn opened 5 years ago

bawpcwpn commented 5 years ago

Hi!

Trying to use this with react-admin 2.7.1 and when using a I get the following error when clicking on the field:

TypeError: _this.props.utils.getStartOfMonth is not a function

The versions for my other packages are: "@date-io/date-fns": "^1.1.0", "date-fns": "^2.0.0-alpha.27",

If I can provide any other info, please let me know!

cmf2903 commented 5 years ago

Solved it by adding below line after importing the utils import DateFnsUtils from '@date-io/date-fns'

DateFnsUtils.prototype.getStartOfMonth = DateFnsUtils.prototype.startOfMonth

Ref: https://github.com/dmtrKovalenko/material-ui-pickers/issues/877#issuecomment-461043769

And when getting an error related to awareOfUnicodeTokens need to set to true, need change the format from DD and YYYY to dd and yyyy respectively.

Ref: https://blog.date-fns.org/post/unicode-tokens-in-date-fns-v2-sreatyki91jg