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

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

rickbarnsleyrickbarnsley Posts: 8Questions: 2Answers: 0

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

  • allanallan Posts: 61,662Questions: 1Answers: 10,094 Site admin
    Answer ✓

    Hi Rick,

    I'm using Require.JS to AMD load moment

    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 for window.moment. If moment 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

  • rickbarnsleyrickbarnsley Posts: 8Questions: 2Answers: 0

    Thanks Allan - that's done the trick.

  • edboyeredboyer Posts: 3Questions: 0Answers: 0

    with angular, I had to use window['moment'] = moment;

This discussion has been closed.