Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Name attribute shows empty when creating custom fields on product creation form #9944

Closed
PatrickSH opened this issue Jun 14, 2017 · 8 comments
Assignees
Labels
Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release

Comments

@PatrickSH
Copy link

PatrickSH commented Jun 14, 2017

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.

Preconditions

  1. Linux - Ubuntu
  2. Mysql 5.6
  3. PHP 7.0.12
  4. Magento 2.1.5

Steps to reproduce

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

Expected result

Name attribute should not be blank

Actual result

Name attribute shows up blank

@SilvanLaroo
Copy link

Same issue here, added fields by using a Modifier. Fields are shown fine, but the name attribute is empty.

@magento-engcom-team magento-engcom-team added the Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed label Sep 11, 2017
@magento-engcom-team magento-engcom-team added Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed and removed Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed labels Oct 2, 2017
@magento-engcom-team magento-engcom-team added the Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed label Oct 9, 2017
@magento-engcom-team
Copy link
Contributor

@PatrickSH, thank you for your report.
We've created internal ticket(s) MAGETWO-81311 to track progress on the issue.

@magento-engcom-team magento-engcom-team added 2.1.x Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release labels Oct 9, 2017
@briscoda
Copy link

I am working on it. #SQUASHTOBERFEST

@briscoda
Copy link

briscoda commented Oct 23, 2017

This seems to happen when the product_form.xml field name is a one-word string without a '.'.

See: https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/Ui/view/base/web/js/form/element/abstract.js#L122

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.

issue_9944_2

issue_9944_1

@okorshenko
Copy link
Contributor

Hi @briscoda please accept the invite on the GitHub

@magento-team
Copy link
Contributor

Internal ticket to track issue progress: MAGETWO-82537

@okorshenko
Copy link
Contributor

The issue has been fixed in 2.2-develop branch and will be available with 2.2.2 release soon

@magento-team
Copy link
Contributor

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.

@magento-team magento-team added the Fixed in 2.3.x The issue has been fixed in 2.3 release line label Jan 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release
Projects
None yet
Development

No branches or pull requests

6 participants