2 Comments

_create function in custom require.js not called

Is there anyway to restrict min qty limit for config product?
my pay pal logo has disappeared from my cms static block

I am creating a custom js for my module.

app/code/Namespace/Module/view/frontend/requirejs-config.js

var config = {
    map: {
        '*': {
            myjs:'Namespace_Module/js/myjs'
        }
    }
};

app/code/Namespace/Module/view/frontend/web/js/myjs.js

define([
    "jquery",
    "underscore",
    "jquery/ui"
],
    function($, _){
        console.log('1');
        $.widget('mage.myjs', {
            options: {
                divId: '',
                ajaxUrl: '',
                isNeedLast: false,
                autoSubmit: false,
            },
            selects: [],
        _create: function() {
            console.log('inside create'); // this log is not displayed
        }
    });

    return $.mage.myjs;

});

and calling it in the phtml like below :

require(['jquery', 'myjs'], function($) {
        var finderConfig = {"ajaxUrl":"<?php echo $block->getAjaxUrl() ?>","isNeedLast":1,"autoSubmit":1};
        finderConfig.divId = 'finder_<?php echo $finderID ?>';
        $("#finder").myjs(finderConfig);
    });

here the console.log('1') is displayed but the console.log('inside create') inside _create function is not displayed.

cany anyone point out what i am missing.Thanks.

Related Posts

  • Modifying authentication popup (0)
    I'm trying to apply the authentication popup on a custom button in my module. I've implemented it by overriding it in my requirejs-config. var config = { map: { '*': { 'Magento_Customer/js/model/authentication-popup': […]
  • RequireJS Error – require.js:166 Uncaught Error: Mismatched anonymous define() module: function (){return Z} (0)
    I'm new to RequireJS and trying to figure out why this is happening. I have a custom file stickyNav.js in <vendor>/<theme>/web/js. I've added a requirejs-config.js file in <vendor>/<theme>/web/. var config = { map: { '*' : { […]
  • Magento 2 RequireJs callback not called (0)
    I have the following in requirejs-config.js var config = { "map": { "*": { "jquery/easing": "./js/jquery.easing.1.3", "jquery/mobile/customized": "./js/jquery.mobile.customized.min", "camera": "./js/camera.min" } }, […]
  • java script 404 error in custom module (3)
    I created one module and i want to add js file to that module but in DOM i am getting "404 not found" my file are MyHelloworldviewfrontendrequirejs-config.js var config = { map: { '*': { test1: 'My_Helloworld/js/test1' } […]
  • java script 404 error in custom module (3)
    I created one module and i want to add js file to that module but in DOM i am getting "404 not found" my file are MyHelloworldviewfrontendrequirejs-config.js var config = { map: { '*': { test1: 'My_Helloworld/js/test1' } […]
  • jQuery Function Call issue (1)
    I'm using magento 1.9 version. I am creating custom module, which contains some javascript functions to be included. I defined all javascript functions in seperate js file and included that js in my xml file under appdesignmythemedefault. Called the js function in my phtml file. […]
  • custom js/css file not getting called through phtml- 404 error (1)
    Im trying to creating a custom js file in my custom module. This is what i have tried. viewfrontendrequirejs-config.js var config = { map: { '*': { test: 'Vendor_Module/js/test' } } }; viewfrontendlayoutdefault.xml <?xml version="1.0"?> <page […]
  • custom js/css file not getting called through phtml- 404 error (1)
    Im trying to creating a custom js file in my custom module. This is what i have tried. viewfrontendrequirejs-config.js var config = { map: { '*': { test: 'Vendor_Module/js/test' } } }; viewfrontendlayoutdefault.xml <?xml […]
  • Magento 2: How to override core js module price-bundle.js (3)
    I am attempting to override the _onQtyFieldChanged event in the mage.priceBundle widget in the module-bundle/view/base/web/js/price-bundle.js file. I am referencing the Magento dev docs (http://devdocs.magento.com/guides/v2.0/javascript-dev-guide/javascript/custom_js.html) and this […]
  • How to override _UpdatePrice function in vendormagentomodule-swatchesviewfrontendwebjsswatch-renderer.js (1)
    in my appcodeXYviewfrontendrequirejs-config.js I have: var config = { map: { '*': { 'configurable':'X_Y/js/configurable', 'swatchRenderer':'X_Y/js/swatchRenderer' } } }; in my appcodeXYviewfrontendwebjsswatch_renderer.js I have […]
Is there anyway to restrict min qty limit for config product?
my pay pal logo has disappeared from my cms static block

2 Comments on this article

  • User November 12, 2016

    Add below code in your phtml file.

    <div id="finder"></div>
    <script>
        require(['jquery', 'myjs'], function($) {
            var finderConfig = {"ajaxUrl":"<?php echo $block->getAjaxUrl() ?>","isNeedLast":1,"autoSubmit":1};
            finderConfig.divId = 'finder_<?php echo $finderID ?>';
            $("#finder").myjs(finderConfig);
        });
    </script>
    

    I think you are missing div with id=”finder” in your code. please check it with this code.

    let me know if you have any issue.

    Reply

  • User November 12, 2016

    Try it:

    app/code/Namespace/Module/view/frontend/web/js/myjs.js

    define([
        "jquery",
        "underscore",
        "jquery/ui"
    ],
    function ($) {
        'use strict';
            console.log('1');
            $.widget('mage.myjs', {
                options: {
                    divId: '',
                    ajaxUrl: '',
                    isNeedLast: false,
                    autoSubmit: false,
                },
            _create: function() {
                console.log('inside create');
            }
        });
        return $.mage.myjs;
    });
    

    and calling it in the phtml like below :

    <script type="text/x-magento-init">
        {
            "*": {
                "myjs": {
                        "divId": "finder_" + <?php echo json_encode($finderID) ?>,
                        "ajaxUrl": <?php echo json_encode($block->getAjaxUrl()) ?>,
                }
            }
        }
    
    </script>
    

    Reply

Add a comment

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax