momentLocalizer is undefined in react-widgets-moment.js
I've tried this with both 3.0.0 and 3.1.3. The documentation states that I only need the following files in my script tags:
react-widgets/dist/react-widgets.js react-widgets/dist/react-widgets-moment.js
I've confirmed that these files are actually loaded and executed. The problem that I am running into is that when the DateTimePicker is used, I get the following error:
Error: [React Widgets] You are attempting to use a widget that requires localization (Calendar, DateTimePicker, NumberPicker). However there is no localizer set. Please configure a localizer.
I am loading react v0.14.6 and moment v2.11.1 before I load up the react-widgets scripts.
I'm also noticing that the following functions/objects are undefined:
- momentLocalizer
- window.momentLocalizer
- document.momentLocalizer
- ReactWidgets.momentLocalizer
- ReactWidgets.utils.momentLocalizer
- ReactWidgets.configure
Uncaught ReferenceError: momentLocalizer is not defined
In fact, I don't even see momentLocalizer in any of the source files. I did see an assignment of globalizeLocalizer to exports['default'], but am uncertain in how to access it.
My bower file has the following dependencies:
{
"moment": "~2.11.1",
"react": "0.14.6",
"react-widgets": "~3.1.3"
}
I've also tried using the suggested globalize as well, but I started going down a rabbit hole trying to setup other dependencies for cldr and hunting down how to setup data for it with bowercc. I found that globalizeLocalizer did not exist either, even though the react-widgets/dist/react-widgets-globalize.js file was loaded.
The localizer files don't actually create any globals instead they config themselves against the globally available ReactWidgets (https://github.com/jquense/react-widgets/blob/master/dist/react-widgets-moment.js#L112)
Any chance you can step into the code at that point and see whats going on? Perhaps you somehow have two instances of ReactWidgets loaded...
And yeah I am not sure you can even setup the new Globalize from bower, that project is sort of a rats nest of configs (we just use pre 1.0.0 which is dirt simple to setup)
It appears that there is a function createWrapper that is setting up a dummy object if process.env.NODE_ENV is not equal to 'production'. The value I have is undefined. I also see that process.title === 'browser'. The get method is setup to always return an error unless it is in production.
The date-picker render is assigning format: getFormat(this.props) when _react2['default'].createEleemnt(_DateInput2['default'] is defined.
I do see two calls, but I am uncertain as to why this happens.
Error: [React Widgets] You are attempting to use a widget that requires localization (Calendar, DateTimePicker, NumberPicker). However there is no localizer set. Please configure a localizer.
see http://jquense.github.io/react-widgets/docs/#/i18n for more info.
at Object.get [as formats] (react-widgets.js:916)
at Object.getFormat (react-widgets.js:886)
at getFormat (react-widgets.js:7060)
at render (react-widgets.js:6809)
at 33.ReactCompositeComponentMixin._renderValidatedComponentWithoutOwnerOrContext (react.js:5941)
at 33.ReactCompositeComponentMixin._renderValidatedComponent (react.js:5961)
at 71.ReactPerf.measure.wrapper [as _renderValidatedComponent] (react.js:12346)
at 33.ReactCompositeComponentMixin.mountComponent (react.js:5574)
at 71.ReactPerf.measure.wrapper [as mountComponent] (react.js:12346)
at Object.76.ReactReconciler.mountComponent (react.js:12971)
The createWrapper thing is correct, if nothing replaces the wrapper it throws, which is what is happening. I mean specifically if you can debug whether that line I have linked above is hit. If this error happens before that then you are attempting to use a widget before the localizer is set, i.e the script executes.
Ok, I believe it was rendering twice because the props were being assigned/updated, resulting in getFormat to be called again each time the component render method is called. I've got it setup to only have 1 call. Same problem though.
Again the rendering multiple times is not the problem, Rendering ANY datepicker at all before the localizer script loads will rightfully cause an error.
I mean specifically if you can debug whether that line I have linked above is hit. If this error happens before that then you are attempting to use a widget before the localizer is set, i.e the script executes.
can you please try the above, thanks
That line is not being called to setDateLocalizer. However, exports['default'] is being assigned when the file loads.
Ok I think I found the issue... one sec
I'm not sure if this is related, but I'm noticing there is a module missing in react-widgets-moment.js. I see functions under /* 0 */ through /* 3 */ - except for /* 2 */. Instead, there is just a comma without a value in the array. Also, moduleId in __webpack_require__ is 0, 1, and 3. 2 is never used.
should be fixed in 3.1.4 (just released)
one sec and i'll check
I'm not seeing 3.1.4 in the releases here.
https://github.com/jquense/react-widgets/releases/tag/v3.1.4
Sweet! Confirmed as working. Thanks. :+1: