简体   繁体   中英

Including Moment.js in LiveCycle Designer

For few days I've been trying to include the actual Moment.js library in my dynamic PDF which I've created with Adobe Livecycle Designer.

We've used an older version (1.7.2) without any problems but now I only get a 'Function not exist' error.

Does anyone have any expierience with this?

Thanks in advance.

How to include Moment.js in an Adobe LiveCycle Form:

  1. Download the minified script
  2. In LiveCycle Designer open your form and create a Script Object called MOMENTJSMIN
  3. Copy the minified script into that Script Object
  4. In the Script Editor window of LiveCycle Designer, edit MOMENTJSMIN Script Object in the following manner:
  5. Remove all the script up to but not including the second curly brace { :

     !function(a,b){"object"==typeof exports&&"undefined"!=typeof module?module.exports=b():"function"==typeof define&&define.amd?define(b):a.moment=b()}(this,function() 
  6. Remove the rounded parenthesis and semicolon from the end of the minified script

  7. Add this line to the beginning of the minified script:

     if (xfa.momentjs == undefined) xfa.momentjs = function() 
  8. In the MOMENTJSMIN Script Object add this function after the end of the script:

     function getMomentJS(){ return xfa.momentjs(); } 

Now your MOMENTJSMIN script object is set up to provide Moment.js to scripts throughout your form.

To use Moment.js in any of your script, start your script object or event script with this line:

var moment = MOMENTJSMIN.getMomentJS();

Now you can use moment() anywhere in the script that starts with that line. eg:

var moment = MOMENTJSMIN.getMomentJS();
var jan07 = moment([2007, 0, 29]);
app.alert(moment().format("dddd, MMMM Do YYYY, h:mm:ss a"));
app.alert(jan07.format("dddd, MMMM Do YYYY") + " was " + jan07.fromNow());
app.alert(moment.isDate(new Date()));

What I would check first:

  • Make sure your script is fully loaded before trying to invoke functions from it. (check the event, where you call the function-calculate, form:readty etc.)
  • Check the script referencing. Right path? Right name?
  • Check if the function really exists
  • Check function parameters.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM