2

Hi I have created a mixin but it gives the error "mixin is not a function".

Vendor/CustomCustomer/view/base/web/customercustom.js

define([
    'jquery',
    'underscore',
    'uiRegistry',
    'Magento_Ui/js/form/element/select',
    'domReady!'
], function ($,_, uiRegistry, Select) {
    'use strict';
    $(function() {
    return function (Select) {
        return Select.extend({
            initialize: function (value) {
                this._super();
                var customerCompany = uiRegistry.get('index = customer_company');
                var defaultCompany = uiRegistry.get('index = extension_attributes.company_attributes.company_id');
                var vessels = uiRegistry.get('index = customer_vessels');
                var customerUsername = uiRegistry.get('index = customer_username');
                var password = uiRegistry.get('index = password');
                var cnfpassword = uiRegistry.get('index = confirm_password');
                if (this.value() != 1) {
                    customerCompany.show();
                    defaultCompany.hide();
                    vessels.show();
                    customerUsername.show();
                    password.show();
                    cnfpassword.show();
                } else {
                    customerCompany.hide();
                    defaultCompany.show();
                    vessels.hide();
                    customerUsername.hide();
                    password.hide();
                    cnfpassword.hide();
                }                
                return this;
            },
            onUpdate: function (value) {
                var customerCompany = uiRegistry.get('index = customer_company');
                var defaultCompany = uiRegistry.get('index = extension_attributes.company_attributes.company_id');
                var vessels = uiRegistry.get('index = customer_vessels');
                var customerUsername = uiRegistry.get('index = customer_username');
                var password = uiRegistry.get('index = password');
                var cnfpassword = uiRegistry.get('index = confirm_password');
                if (value != 1) {
                    customerCompany.show();
                    defaultCompany.hide();
                    customerUsername.show();
                    password.show();
                    cnfpassword.show();
                } else {
                    customerCompany.hide();
                    defaultCompany.show();
                    customerUsername.hide();
                    password.hide();
                    cnfpassword.hide();
                    vessels.hide();
                }

                return this._super();
            },
        });
    }
});
  });

Vendor/CustomCustomer/view/base/requirejs-config.js

var config = {
    'config': {
        'mixins': {
            'Magento_Ui/js/form/element/website': {
                'Vendor_CustomCustomer/customercustom': true
            }
        }
    }
};

2 Answers 2

2

You probably need to check and change the location of your mixin.
Refer to the documentation

Update: Remove single quotes in your mixins declaration:
reference

var config = {
    config: {
        mixins: {
            'Magento_Ui/js/form/element/website': {
                'Vendor_CustomCustomer/customercustom': true
            }
        }
    }
};
7
  • Thanks for the response magefms. I have changed the location of my mixin to js/form/element/customercustom. But it is still giving the same error. Please help. May 3, 2019 at 9:21
  • you mean web/js/form/element/customercustom ?
    – fmsthird
    May 3, 2019 at 9:31
  • Yes web/js/form/element/customercustom May 3, 2019 at 10:18
  • so in your require js it looks like this 'Vendor_CustomCustomer/js/form/element/customercustom': true ?
    – fmsthird
    May 3, 2019 at 10:25
  • Yes, it looks like this. May 3, 2019 at 10:27
1

If you're having issues with mixin:

  • Make sure you're using define(), not require(). That was the issue for me.

  • If you're trying to extend a $.widget, don't include the parent widget as a dependency inside define(). It's useless and can create silent errors. Declaring define(['jquery'], ... should be enough.

1
  • 1
    You saved my life
    – jstuardo
    Jul 28, 2021 at 17:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.