Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 841
10 Gauge Avatar asked Aug 16 '17 17:08

10 Gauge


2 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>
like image 87
Granit Krasniqi Avatar answered Sep 30 '22 05:09

Granit Krasniqi


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;
 }
like image 23
Kevin Chavez Avatar answered Sep 30 '22 04:09

Kevin Chavez