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]

Also I have attached the screenshots of the error I am facing. Add productError

A help to fix this issue would be much appreciated.

  • any luck? i had the same after magento upgrade 2.2.2 – Antonio Pedicini Dec 28 '17 at 14:14

The reason this probably fails is because you are retrieving data from database as a string.

You should edit your DataProvider ( Namespace/Module/Model/Test/DataProvider.php ) and change the getData() method with something like

foreach ($items as $test) {
    $this->loadedData[$test->getId()] = $test->getData();
    $customAttributes = ['Test1', 'Test2']; // here you should do your own retrieving of data from the database
    $this->loadedData[$test->getId()]['custom_attribute'] = $customAttributes;
    return $this->loadedData;

This did the trick for me because I add the multiselect in a UI component that relies on a DataProvider.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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