Uncaught Typeerror: Data. Some Is Not a Function

I am trying to figure out a JS error I am receiving in a Magento e-commerce extension that I paid good money for, but support has been lacking on their end to fix this. Error causes a spinning wheel of doom on page load that never goes away.

The following is the error I receive in the developer console:

Uncaught TypeError: data.some is not a function
at findFirst (select.js:67)
at UiClass.normalizeData (select.js:193)
at UiClass.normalizeData (wrapper.js:109)
at UiClass.getInitialValue (abstract.js:200)
at UiClass.setInitialValue (abstract.js:143)
at UiClass._super (wrapper.js:106)
at UiClass.setInitialValue (select.js:302)
at UiClass.setInitialValue (wrapper.js:109)
at UiClass.initialize (abstract.js:70)
at UiClass.initialize (wrapper.js:109)

This is the code section at line 67 of select.js data.some(function (node) { the error is referencing:

/**
 * Recursively loops over data to find non-undefined, non-array value
 *
 * @param  {Array} data
 * @return {*} - first non-undefined value in array
 */
function findFirst(data) {
    var value;

    data.some(function (node) {
        value = node.value;

        if (Array.isArray(value)) {
            value = findFirst(value);
        }

        return !_.isUndefined(value);
    });

    return value;
}

I am hoping this is just some kind of typo error that I might be able to fix on my own?

Thanks in advance for any help.

P.S. I am a coding novice.

7

3 Answers

I've got this issue while creating a form using UI Components, specifically Select component. I was missing the caption element, so if anybody encounter this issue they might be missing an element.

<form>
...
<fieldset>
    ...
    <field name="select_example" formElement="select">
        <settings>
            <dataType>text</dataType>
            <label translate="true">Select Example</label>
            <dataScope>select_example</dataScope>
        </settings>
        <formElements>
            <select>
                <settings>
                    <options>
                        <option name="1" xsi:type="array">
                            <item name="value" xsi:type="string">1</item>
                            <item name="label" xsi:type="string">Option #1</item>
                        </option>
                        <option name="2" xsi:type="array">
                            <item name="value" xsi:type="string">2</item>
                            <item name="label" xsi:type="string">Option #2</item>
                        </option>
                        <option name="3" xsi:type="array">
                            <item name="value" xsi:type="string">3</item>
                            <item name="label" xsi:type="string">Option #3</item>
                        </option>
                    </options>
                    <caption translate="true">-- Please Select --</caption>
                </settings>
            </select>
        </formElements>
    </field>
1

In Magento 2.1.8 there was a method removed that may affect certain extensions - it affected ours called getOptionArray().

To fix it in our extension in: Ui/DataProvider/Product/Form/Modifier/FixedSelectionType.php

'options' => FixedType::getOptionArray(),

becomes:

'options' => FixedType::getOptionsArray(),

and in the model/attribute folder add this method, in our case the full path is: Model/Attribute/Sources/FixedType.php

and above the public function getalloptions() method add this:

public static function getOptionsArray()
 {
     $result = [];

     foreach (self::getOptionArray() as $index => $value) {
         $result[] = ['value' => $index, 'label' => $value];
     }

     return $result;
 }

I got this issue in Magento 2.2.3 version too. The issue was found with the file, vendor/magento/module-ui/view/base/web/js/form/element/select.js. We need to override and add the changes to the file as below. Find the code,

data.some(function (node) {
    value = node.value;

    if (Array.isArray(value)) {
        value = findFirst(value);
    }

    return !_.isUndefined(value);
}); 

Replace with the updated code,

data = _.some(data, function (node) {
    value = node.value;
    if (Array.isArray(value)) {
        value = findFirst(value);
    }

    return !_.isUndefined(value);
});  

This solved the issue for me. Thanks!

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.

Maya Lin-Takahashi

Maya Lin-Takahashi

Consumer Tech & Gadget Reviewer

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.

Share this article
Twitter Facebook Pinterest