How does Editor recognise that Moment.JS is loaded for formatting dates?
How does Editor recognise that Moment.JS is loaded for formatting dates?

Hi,
Am trying to follow the straightforward example at https://editor.datatables.net/examples/dates/formatting.html in order to format some dates returned in YYYY-MM-DD format into something more user friendly.
Moment.JS is being loaded on the page prior to any of the datatables files being loaded, however I still get "Uncaught Editor datetime: Without momentjs only the format 'YYYY-MM-DD' can be used" in the console window when I try to alter the format.
I'm using Require.JS to AMD load moment - it's used thorughout the rest of my stack in a similar way. For me to create a test harness illustrating the problem will be very time consuming, so I'm wondering if by asking the question a different way we'll be able to short-circuit the analysis. How does the Editor library determine whether moment.js is loaded? Maybe I can expose the moment library to Editor somehow?
Cheers,
Rick
This question has an accepted answers - jump to answer
Answers
Hi Rick,
Right, that's the issue here. Because Editor can't assume that Moment will always be loaded, I can't add it to its own
require
chain. So instead it simply looks forwindow.moment
. Ifmoment
isn't globally defined then Editor currently won't use it.As a workaround for the moment if you use
window.moment = moment;
inside your loader, before initialising Editor that should do it.Allan
Thanks Allan - that's done the trick.
with angular, I had to use window['moment'] = moment;