[Custom Input Masks] DecimalDigits set to 0 in CurrencyMask ends up with 2 digits anyway

Forge Component
(43)
Published on 9 Mar (3 weeks ago) by Marcelo Ferreira
43 votes
Published on 9 Mar (3 weeks ago) by Marcelo Ferreira

I am not sure this is a bug or a feature, but when we use 0 for the property DecimalDigits in a MaskCurrency we end up with 2 digits anyway. I looked at the javascript for currency and it says this:

if (decimalDigits != 0) {
        maskOpts = $.extend(maskOpts, {
                digits: decimalDigits
            });
    }

I tried setting my locale options to 0 digits but it's not listening to locale settings either when no digits option is provided in maskOpts.

My hack is the following: I set the DecimalDigits option to -1, this way the if branch is entered and the setting is applied. 

The result is 0 digits in my mask!



I have the newest version of CustmInputMask and I have the same promlem as Wendy Tromp.

I put in 0 decimalDigits but still I end up with two zeros as decimal digits.

The -1 hack is not working for me because I have a Suffix and that ends up adding four zeros to every number I write.



Hi,

Sry for the late reply. This is fixed on the latest version.

Regards,

Marcelo

Hi Marcelo,

Will this be fixed for Outsystems 10 as well?

Thanks.

Hi Rafel,

I don't have access to a environment with version 10 to make that happen. But if you want to do it yourself you just need to open the component, find the MaskCurrency widget and select the widget JS. On that JS delete the following:

if (decimalDigits != 0) {
        maskOpts = $.extend(maskOpts, {
                digits: decimalDigits
            });
    }

Regards,

Marcelo

Hello Marcelo,

Removed the following code as suggested, but still getting 2 decimal digits.

Code that was left on the widget:


SyntaxEditor Code Snippet

// Aux javascript functions
function OSPage_InputMaskCurrency(elementID, decimalDigits, prefixText, suffixText, decimalSep, groupSep, options, keepMask) {
    var mask = "currency";
    var maskOpts = $.extend(options, {
            radixPoint: decimalSep,
            groupSeparator: groupSep,
            suffix: suffixText,
            prefix: prefixText,
            autoGroup: true,
            autoUnmask: true,
            removeMaskOnSubmit: true,
            onUnMask: function (maskedValue, unmaskedValue, maskOpts) {
                if (unmaskedValue === "" && maskOpts.nullable === true) {
                    return unmaskedValue;
                }
                var processValue = maskedValue.replace(maskOpts.prefix, "");
                processValue = processValue.replace(maskOpts.suffix, "");
                processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(maskOpts.groupSeparator), "g"), "");
                if (maskOpts.radixPoint !== "" && processValue.indexOf(maskOpts.radixPoint) !== -1)
                    processValue = processValue.replace(Inputmask.escapeRegex.call(this, maskOpts.radixPoint), ".");

                return processValue;
            }
        });
    $(elementID).inputmask(mask, maskOpts);
    if (keepMask == "False") {
        var Base_OsPage_ClientValidate = OsPage_ClientValidate;
        OsPage_ClientValidate = (function (srcElement, cleanOnlySrcElementErrors) {
            $(elementID).inputmask('remove');
            var result = Base_OsPage_ClientValidate(srcElement, cleanOnlySrcElementErrors);
            $(elementID).inputmask(mask, maskOpts);
            return result;
        });

        osAjaxBackend.BindBeforeSubmit(function () {
            $(elementID).inputmask('remove');
        });
        osAjaxBackend.BindAfterSubmit(function () {
            $(elementID).inputmask('remove');
            $(elementID).inputmask(mask, maskOpts);
        });
    }
}

I tried adding decimal options on the first block that the options were being set, but got no success.

Thanks.

Hi Rafael,

Sry I forgot you also need to add the digits options to the code like this:

SyntaxEditor Code Snippet

    var maskOpts = $.extend(options, {
            digits: decimalDigits,
            radixPoint: decimalSep,

Regards,

Marcelo

Hello Marcelo,

I tried it yesterday but i think i was doing something wrong, with your code snippet it worked like a charm.

Thanks a lot.

Regards,

Rafael