I have created a custom attribute(multiselect) for product with the same filter type as category selection on Magento 2. Attribute selection is working fine when creating a new product however it is not working on edit form. I have noticed below error from knockout js on console.

knockout.js:1449 Uncaught TypeError: Cannot read property 'apply' of undefined at Function.ko.observableArray.fn.(anonymous function) [as push]

i modified the component by adding the following code

'arguments' => [
                'data' => [
                        'elementTmpl' => 'ui/grid/filters/elements/ui-select',
                        'filterOptions' => true,
                        'multiple' => true,
                        'disableLabel' => true,
                        "showCheckbox" => true,

Also I have attached the screenshots of the error I am facing. enter image description here enter image description here

A help to fix this issue would be much appreciated.

1 Answer 1


Here i found the answer myself

when we convert product multi-select attribute to ui-component(like as category) the main issue is occurs at the time of loading the product-edit-form like according the above question at the time of creating of product it will save the data correctly but when we open product-edit-form the attribute gets the data in the from of comma separated string but the multi select ui component need the data in the form of array. So just Convert the String into the Array and your problem has been Solved :)

Here is the Piece of code which is used for solved the problem

In your DataProvider file you need to override getMeta()

public function modifyData(array $data) {
        //here data is the array of UI Component
       //we are modifying the data of the array

    $model = $this->locator->getProduct();
    $modelId = $model->getId();
    $path = $modelId . '/' . self::DATA_SOURCE_DEFAULT . '/' . 'your_attribute_id'; 
    $dataString = $data[$modelId][self::DATA_SOURCE_DEFAULT][$path];
    $dataArray = explode(',', $dataString);
    $data = $this->arrayManager->remove($path, $data);
    $data = $this->arrayManager->set($path,$data,$dataArray);     
    return $data;

Hope it will help :)

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.