When i try to add new fields to product creationgform in the html name attribute shows up empty, i tried to add the new field both by extending product_form.xml and by using a modifier but both approches ends up the same - a empty name attribute.
I also added these custom fields to
category_form.xml
cms_page_form.xml
Using the exact same method and here it works perfectly.
1. Extend product_form.xml to your custom module Vendor/Component/view/adminhtml/ui_component/product_form.xml
2. Add the code you need for the custom field to show up i will show my code of both modifier and by using pure XML
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright 漏 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<fieldset name="hidden_fields"><!-- Hidden fields -->
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="collapsible" xsi:type="boolean">false</item>
<item name="label" xsi:type="string" translate="true">Label</item>
<item name="sortOrder" xsi:type="number">200</item>
<item name="display" xsi:type="string">false</item>
<item name="additionalClasses" xsi:type="string">hiddenFieldSet</item>
</item>
</argument>
<field name="holder">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="dataType" xsi:type="string">string</item>
<item name="formElement" xsi:type="string">input</item>
<item name="additionalClasses" xsi:type="string">holder</item>
</item>
</argument>
</field>
<field name="another_holder">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="dataType" xsi:type="string">string</item>
<item name="formElement" xsi:type="string">input</item>
<item name="additionalClasses" xsi:type="string">another_holder</item>
</item>
</argument>
</field>
</fieldset>
<fieldset name="fields">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="collapsible" xsi:type="boolean">false</item>
<item name="label" xsi:type="string" translate="true">fields</item>
<item name="sortOrder" xsi:type="number">300</item>
<item name="additionalClasses" xsi:type="string">shownFieldSet</item>
</item>
</argument>
<field name="addfield">
<argument name="data" xsi:type="array">
<item name="options" xsi:type="object">VEndor\Namespace\Ui\Component\Listing\Page\Options</item>
<item name="config" xsi:type="array">
<item name="dataType" xsi:type="string">int</item>
<item name="label" xsi:type="string" translate="true">Tilf酶j nyt felt</item>
<item name="formElement" xsi:type="string">select</item>
<item name="dataScope" xsi:type="string">new_block</item>
<item name="default" xsi:type="string">0</item>
</item>
</argument>
</field>
</fieldset>
</form>
Using modifier
<?php
namespace Vendor\Namespace\Ui\Component\Form;
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier;
use Vendor\Namespace\Ui\Component\Listing\Page\Options as SelectOptions;
class AddFillFieldsData extends AbstractModifier
{
public function __construct(
SelectOptions $SelectOptions
)
{
$this->selectOptions = $SelectOptions;
}
public function modifyMeta(array $meta)
{
$meta['fields'] = [
'arguments' => [
'data' => [
'config' => [
'label' => __('Feields'),
'sortOrder' => 300,
'collapsible' => true,
'componentType' => 'fieldset'
]
]
],
'children' => [
'new_field' => [
'arguments' => [
'data' => [
'config' => [
'formElement' => 'select',
'componentType' => 'field',
'options' => $this->selectOptions->toOptionArray(),
'visible' => 1,
'dataScope' => "new_field",
'required' => 0,
'label' => __('Tilf酶j nyt felt')
]
]
]
]
]
];
return $meta;
}
/**
* {@inheritdoc}
*/
public function modifyData(array $data)
{
return $data;
}
}
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="fields" xsi:type="array">
<item name="class" xsi:type="string">Vendor\Namespace\Ui\Component\Form\AddFillFieldsData</item>
<item name="sortOrder" xsi:type="number">1000</item>
</item>
</argument>
</arguments>
</virtualType>
</config>
3. Clear cache and recompile You should now see the field with a blank name attribute
Name attribute should not be blank
Same issue here, added fields by using a Modifier. Fields are shown fine, but the name attribute is empty.
@PatrickSH, thank you for your report.
We've created internal ticket(s) MAGETWO-81311 to track progress on the issue.
I am working on it. #SQUASHTOBERFEST
This seems to happen when the product_form.xml field name is a one-word string without a '.'.
In the xml referenced by the original reporter, if it was replaced like this:
<?xml version="1.0" encoding="UTF-8"?>
...
<field name="holder.extra">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="dataType" xsi:type="string">string</item>
<item name="formElement" xsi:type="string">input</item>
<item name="additionalClasses" xsi:type="string">holder</item>
</item>
</argument>
</field>
...
The name attribute would get inserted as "extra" because of the way the data ends up when the javascript tries to split and slice it.
In the working example of the category_form.xml, whether it is one word or two words separated by a ".", the name attribute would get rendered either as, "holder" or "holder[extra]".
To resolve this correctly, I think you would need to find where it is responsible for parsing the 'product_form.xml' and make sure that it matches the same way that the xml is parsed on the category creation form as well.
I am looking for where this happens now.
It also seems like there should be some kind of a check in the abstract.js line referenced above to see if there is an undefined value there.


Hi @briscoda please accept the invite on the GitHub
Internal ticket to track issue progress: MAGETWO-82537
The issue has been fixed in 2.2-develop branch and will be available with 2.2.2 release soon
Hi @PatrickSH. Thank you for your report.
The issue has been fixed in magento-engcom/magento2ce#1284 by @magento-engcom-team in 2.3-develop branch
Related commit(s):
The fix will be available with the upcoming patch release.
Most helpful comment
Hi @PatrickSH. Thank you for your report.
The issue has been fixed in magento-engcom/magento2ce#1284 by @magento-engcom-team in 2.3-develop branch
Related commit(s):
The fix will be available with the upcoming patch release.