No new record when clicking the add button in the dynamic rows
-
14-04-2021 - |
Question
when I click the add button of the dynamic rows that I added in the custom tab on the product edit page, it remains in loading. Does anyone know the solution?
etc/adminhtml/di.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<virtualType name="Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Pool">
<arguments>
<argument name="modifiers" xsi:type="array">
<item name="custom-tab-with-content" xsi:type="array">
<item name="class" xsi:type="string">Vendor\Module\Ui\DataProvider\Product\Form\Modifier\CustomTab</item>
<item name="sortOrder" xsi:type="number">10</item>
</item>
</argument>
</arguments>
</virtualType>
</config>
Vendor\Module\Ui\DataProvider\Product\Form\Modifier\CustomTab
<?php
use Magento\Catalog\Model\Locator\LocatorInterface;
use Magento\Catalog\Model\ProductFactory;
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier;
use Magento\Framework\Phrase;
use Magento\Framework\Stdlib\ArrayManager;
use Magento\Framework\UrlInterface;
use Magento\Ui\Component\Container;
use Magento\Ui\Component\DynamicRows;
use Magento\Ui\Component\Form\Element\ActionDelete;
use Magento\Ui\Component\Form\Element\DataType\Text;
use Magento\Ui\Component\Form\Element\Input;
use Magento\Ui\Component\Form\Element\Select;
use Magento\Ui\Component\Form\Field;
use Magento\Ui\Component\Form\Fieldset;
class CustomTab extends AbstractModifier
{
const FIELDSET_DYNAMIC_ROWS_NAME = 'dynamic_rows';
const FIELD_IS_DELETE = 'actionDelete';
const FIELD_NAME_SELECT = 'select_field';
protected $_backendUrl;
protected $_productLoader;
protected $_modelCustomtabFactory;
protected $_ingredientOptions;
/**
* @var LocatorInterface
*/
protected $locator;
/**
* @var ArrayManager
*/
protected $arrayManager;
/**
* @var UrlInterface
*/
protected $urlBuilder;
/**
* @var array
*/
protected $meta = [];
/**
* @param LocatorInterface $locator
* @param ArrayManager $arrayManager
* @param UrlInterface $urlBuilder
* @param CustomTabFactory $modelFriendFactory
* @param ProductFactory $_productLoader
* @param \Magento\Backend\Model\UrlInterface $backendUrl
* @param IngredientOptions $ingredientOptions
*/
public function __construct(
LocatorInterface $locator,
ArrayManager $arrayManager,
UrlInterface $urlBuilder,
CustomTabFactory $modelFriendFactory,
ProductFactory $_productLoader,
\Magento\Backend\Model\UrlInterface $backendUrl,
IngredientOptions $ingredientOptions
) {
$this->locator = $locator;
$this->arrayManager = $arrayManager;
$this->urlBuilder = $urlBuilder;
$this->_modelCustomtabFactory = $modelFriendFactory;
$this->_productLoader = $_productLoader;
$this->_backendUrl = $backendUrl;
$this->_ingredientOptions = $ingredientOptions;
}
public function modifyData(array $data)
{
return $data;
}
public function modifyMeta(array $meta)
{
$this->meta = $meta;
$this->addCustomTab();
return $this->meta;
}
protected function addCustomTab()
{
$this->meta = array_merge_recursive(
$this->meta,
[
static::FIELDSET_DYNAMIC_ROWS_NAME => $this->getTabConfig(),
]
);
}
protected function getTabConfig()
{
return [
'arguments' => [
'data' => [
'config' => [
'label' => __('Ingredients'),
'componentType' => Fieldset::NAME,
'dataScope' => '',
'provider' => static::FORM_NAME . '.product_form_data_source',
'ns' => static::FORM_NAME,
'collapsible' => true,
'sortOrder' => 10,
],
],
],
'children' => [
'customTab' => [
'arguments' => [
'data' => [
'config' => [
'componentType' => DynamicRows::NAME,
'component' => 'Magento_Ui/js/dynamic-rows/dynamic-rows-grid',
// 'template' => 'Magento_Backend/dynamic-rows/grid',
'defaultRecord' => true,
'addButton' > true,
'links' => [
'insertData' => '${ $.provider }:${ $.dataProvider }'
],
],
],
],
'children' => [
'record' => [
'arguments' => [
'data' => [
'config' => [
'componentType' => Container::NAME,
'component' => 'Magento_Ui/js/dynamic-rows/record',
'isTemplate' => true,
'is_collection' => true,
],
],
],
'children' => [
static::FIELD_NAME_SELECT => $this->getSelectFieldConfig(1),
static::FIELD_IS_DELETE => $this->getIsDeleteFieldConfig(4)
]
]
]
]
]
];
}
protected function getSelectFieldConfig($sortOrder)
{
return [
'arguments' => [
'data' => [
'config' => [
'label' => __('Ingredients'),
'componentType' => Select::NAME,
'formElement' => Select::NAME,
'dataScope' => static::FIELD_NAME_SELECT,
'sortOrder' => $sortOrder,
'options' => $this->_ingredientOptions->getAllOptions(),
'visible' => true,
'disabled' => false,
'validation' => [
'required-entry' => true,
],
],
],
],
];
}
protected function getIsDeleteFieldConfig($sortOrder)
{
return [
'arguments' => [
'data' => [
'config' => [
'componentType' => ActionDelete::NAME,
'fit' => true,
'dataType' => Text::NAME,
'sortOrder' => $sortOrder,
],
],
],
];
}
}
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange