Working with Decimal in a custom widget

1
I ran into issues with a custom widget during sandbox deploy. It seems the deploy does not like that I refer to the JavaScript Big library (for Decimal support) by including big/big in the module list. Locally this works perfectly but the deployment and the check widgets tool choke on my widget, build log has an error about referring to big/big How can I create Big objects in my custom widgets and keep the deployment tools happy? BTW I submitted a pull request on the boilerplate to include big/big as module reference so that is probably not correct... Edit: I created a test widget using Brackets and the boilerplate and added some Decimal stuff to demonstrate the issue. Support ticket: 462839 Test project: https://github.com/mgroeneweg/CrashTestDummies/blob/master/TestDecimalWidget.mpk Edit 2: I convert Decimal to JavaScript Number before using in the calculations. No more big/big reference so no more deployment issue. But only second best because I wanted to use Big objects throughout the pivot table widget for accuracy.
asked
3 answers
0

Think something like this should work? Can't guarantee it because i have not implemented it myself yet. Perhaps it would be handy if you could show your code.

define([
        "dojo/_base/declare",
        "mxui/widget/_WidgetBase",
        "dijit/_TemplatedMixin",
        "mxui/dom",
        "dojo/dom",
        "dojo/dom-prop",
        "dojo/dom-geometry",
        "dojo/dom-class",
        "dojo/dom-style",
        "dojo/dom-construct",
        "dojo/_base/array",
        "dojo/_base/lang",
        "dojo/text",
        "dojo/html",
        "dojo/_base/event",
        //Added Big library as module
        "big/big.min",
        "WidgetName/lib/jquery-1.11.2.min",
        "dojo/text!WidgetName/widget/template/WidgetName.html"
    ], function(declare, _WidgetBase, _TemplatedMixin, dom, dojoDom, dojoProp, dojoGeometry, dojoClass, dojoStyle, dojoConstruct, dojoArray, dojoLang, dojoText, dojoHtml, dojoEvent, _big, _jQuery, widgetTemplate) {
        "use strict";

        var $ = jQuery.noConflict(true);

        // Declare widget's prototype.
        return declare('Test.widget.Test', [_WidgetBase, _TemplatedMixin], {

                   var biggie = new Big();

                   mx.data.get({
                           guid: "yourMendixObjectGUID",
                                   callback: function(obj) {
                                           console.log("Received MxObject with GUID " + obj.getGUID());
                                           biggie = obj.get("DecimalAttributeName"); 
                                           console.log(biggie);
                           }
                  });
        }
answered
0

Could you perhaps share your code example in some way?

I guess because the define() function is lazy, while the require() function isn’t. Modules imported in the define() function, will only be imported at the moment they’re imported in another require() statement. So I'm guessing that might be what was missing because it is very unlikely any of the other modules loaded by the default widget template require big.js.

require({ 
    packages: [{
            //The name might actually have to be big/big
        name: 'big',
            //And I'm not sure if this correct path to the default libraries in Mendix
        location: 'mxclientsystem/big/', 
        main: 'big.min'
    }]
}, define([
    "dojo/_base/declare",
    "mxui/widget/_WidgetBase",
    "dijit/_TemplatedMixin",
    "mxui/dom",
    "dojo/dom",
    "dojo/dom-prop",
    "dojo/dom-geometry",
    "dojo/dom-class",
    "dojo/dom-style",
    "dojo/dom-construct",
    "dojo/_base/array",
    "dojo/_base/lang",
    "dojo/text",
    "dojo/html",
    "dojo/_base/event",
    "big/big",
    "WidgetName/lib/jquery-1.11.2.min",
    "dojo/text!WidgetName/widget/template/WidgetName.html"
],function(declare, _WidgetBase, _TemplatedMixin, dom, dojoDom, dojoProp, dojoGeometry, dojoClass, dojoStyle, dojoConstruct, dojoArray, dojoLang, dojoText, dojoHtml, dojoEvent, big, _jQuery, widgetTemplate) {
    "use strict";

    if (typeof big === 'undefined') {
               throw 'This widget requires Big.js to be loaded first';
    }

    var $ = jQuery.noConflict(true);

    // Declare widget's prototype.
    return declare('Test.widget.Test', [_WidgetBase, _TemplatedMixin], {

               var biggie = new Big();

               mx.data.get({
                       guid: "yourMendixObjectGUID",
                               callback: function(obj) {
                                       console.log("Received MxObject with GUID " + obj.getGUID());
                                       biggie = obj.get("DecimalAttributeName"); 
                                       console.log(biggie);
                       }
              });
    }
})
answered
0

The big library doesn't seem to be included when creating a deployment package, when browsing to projectfolder/deployment/data/tmp/

there is no big reference there, which could explain why the library cannot be found. Perhaps copying the Big.js files to the widget folder will fix your issue. Meaning you will have to load the big library from inside your widget folders similar to how Jquery is loaded.

answered