7

I am using 2 components for multi-select and select input fields.

Multiselect component -

define([
    'underscore',
    'uiRegistry',
    'Magento_Ui/js/form/element/multiselect',
    'Magento_Ui/js/modal/modal',
    'Namespace_Modulename/js/selectoptions'
], function (_, uiRegistry, multiselect, modal,selectoptions) {
    'use strict';

    return multiselect.extend({

        /**
         * On value change handler.
         *
         * @param {String} value
         */
        onUpdate: function (value) {
            console.log(selectoptions.myNew());
            return this._super();
        },
    });
});

Select Component -

define([
    'underscore',
    'uiRegistry',
    'Magento_Ui/js/form/element/select',
    'Magento_Ui/js/modal/modal'
], function (_, uiRegistry, select, modal) {
    'use strict';

    return select.extend({

        myNew: function () {
            console.log('In my new function');
        },
    });
});

I have injected selectoptions component in multi-select component and calling its myNew method onUpdate of multi-select. But I am getting below error.

selectoptions.myNew is not a function

UPDATE

I was able to call the function now using

selectoptions.prototype.myNew();

But still not getting why we need to use prototype here.

2
  • Are you solve this?
    – Mahi M
    Commented Aug 19, 2019 at 11:35
  • Your updated solution saved me
    – GenZ Dev
    Commented Aug 27, 2020 at 15:08

1 Answer 1

1

try call the function use

selectoptions().myNew();

Your Answer

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

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