Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How connect jquery.inputmask using requirejs

How correctly connect https://github.com/RobinHerbots/jquery.inputmask using requirejs? Method on official site documentation not correct.

I try make it like this

require-config.js

paths: {
  ...
  inputmask: "/assets/vendor/jquery.inputmask/dist/inputmask/inputmask",
  dependencyLib: "/assets/vendor/jquery.inputmask/dist/inputmask/dependencyLib",
  jQueryInputmask: "/assets/vendor/jquery.inputmask/dist/inputmask/jquery.inputmask",
  ...
}

script.js

define('script', ['jquery', 'jQueryInputmask'], function ($) {
    ...
    $obj.inputmask(
        {
            alias: 'currency',
            rightAlign: false,
            digits: 0
        }
    );
    ...
});

but it not work

like image 778
sglazkov Avatar asked Oct 06 '15 22:10

sglazkov


1 Answers

Try with this code:

require.config({
    paths: {
        ...
        "jquery"            : "../dist/jquery/jquery",
        "jQueryInputmask"   : "../dist/inputmask/jquery.inputmask",
        "inputmask"         : "../dist/inputmask/inputmask",
        ...
    },
    shim: {
        jquery: {
            exports: "$"
        },
        jQueryInputmask: {
            deps: ["jquery", "inputmask"],
            exports: "$"
        },
)

define('script', ['jquery', 'jQueryInputmask'], function ($) {
    ...
    $obj.inputmask(
        {
            alias: 'currency',
            rightAlign: false,
            digits: 0
        }
    );
    ...
});

In my project it works setting the shim:

shim: Configure the dependencies, exports, and custom initialization for older, traditional "browser globals" scripts that do not use define() to declare the dependencies and set a module value.

like image 137
slorenzo Avatar answered Oct 05 '22 23:10

slorenzo