Hi,
I've followed the Magento 2 dev docs (http://devdocs.magento.com/guides/v2.2/howdoi/customize_product.html) and created a custom ui_component to add an extra fieldset with a nested checkboxset field to the product edit page, but when I click save the custom field values are not included in
$this->getRequest()->getPostValue()
After further inspection I realized that the html 'name' attribute was not being set on the rendered checkboxes.
I'm working with v2.2.2 and my code looks like this.
/etc/adminhtml/di.xml:
<?xml version="1.0"?>
<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="customProductModifier" xsi:type="array">
<item name="class" xsi:type="string">Vendor\Module\Ui\Modifier\Product\Form\CustomProductModifier</item>
<item name="sortOrder" xsi:type="number">1</item>
</item>
</argument>
</arguments>
</virtualType>
/ui_component/product_form.xml:
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<fieldset name="custom_products">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Label</item>
<item name="sortOrder" xsi:type="number">1</item>
<item name="collapsible" xsi:type="boolean">true</item>
</item>
</argument>
<field name="custom_attr" formElement="input">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="formElement" xsi:type="string">checkboxset</item>
<item name="componentType" xsi:type="string">field</item>
<item name="visible" xsi:type="number">1</item>
<item name="sortOrder" xsi:type="number">1</item>
<item name="label" xsi:type="string">Label</item>
<item name="dataScope" xsi:type="string">product[custom_attr]</item>
</item>
</argument>
</field>
</fieldset>
</form>
CustomProductModifier.php:
<?phpnamespace Vendor\Module\Ui\Modifier\Product\Form;
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier;
use Vendor\Module\Service\HTTPService;
class CustomProductModifier extends AbstractModifier{
public function modifyMeta(array $meta){ $meta['custom_products'] = [
'children' => [
'custom_attr' => [
'arguments' => [
'data' => [
'config' => [
'options' => $this->populateValues()
]
]
]
]
]
];
return $meta;
}
public function modifyData(array $data){
return $data;
}
private function populateValues(){ $values = array( array('value' => 'disabled', 'label' => 'Disabled'),
);
foreach(HTTPService::get_instance()->get_data() as $index => $data){ $values[] = array('value' => '$data['title'], 'label' => $data['title']);
}
return $values;
}
}
Any ideas why this is happening or what I can try?
Thanks in advance.