Magento2: UI listing drop-down value issue.

Created on 29 Jul 2016  路  9Comments  路  Source: magento/magento2

Preconditions

Magento 2.1 + sample data

Steps to reproduce

  1. Add to options array value with comma, for example:
    Magento\Cms\Model\Page\Source\PageLayout
public function toOptionArray()
    {
        if ($this->options !== null) {
            return $this->options;
        }

        $configOptions = $this->pageLayoutBuilder->getPageLayoutsConfig()->getOptions();
        $options = [];
        foreach ($configOptions as $key => $value) {
            $options[] = [
                'label' => $value,
                'value' => $key,
            ];
        }

        ///Test
        $options[] = [
            'label' => 'test',
            'value' => 'test, test',
        ];
        ///
        $this->options = $options;
        return $this->options;
    }
  1. For any CMS Page change "Page Layout" value to "test".

    Expected result

  2. You can see "test" on the CMS page grid

    Actual result

  3. Label "test" on the CMS page grid is missing.
    https://www.dropbox.com/s/tzyl3wtaw8cavxt/ssp_temp_capture%20copy.png?dl=0
    But for edit page or edit popup is OK:
    https://www.dropbox.com/s/vljrm98i5ci4x1i/Screenshot%202016-07-29%2017.31.37.png?dl=0

Frontend Cms Confirmed Format is valid Ready for Work P3 ready for dev Reproduced on 2.1.x Reproduced on 2.2.x Reproduced on 2.3.x S3 Dev.Experience bug report

All 9 comments

Hi @sergei-sss,

Can you explain why you expect that there will be any label on cms grid if you have added new option only in toOptionArray() method ? Grid does not know anything about options from toOptionArrat() it know only about options in DB (or other storage).

So it looks like this is not a bug but a wrong usage. You can add values with comma through the appropriate form (e.g. create new attribute value or tax class) and check that commas work.

Thanks for reporting!

Hi @AzVo,

Of course, you should directly add the values to the cms page table (for test aim) or you can save new values from express grid-edit popup - you have already new options, because we have modified OptionArray.

I only want to compare two situation - if value with comma, and without.

Here is the DB screen:
https://www.diigo.com/item/image/4wouz/qpb9

Here is the admin UI grid screen:
https://www.diigo.com/item/image/4wouz/8n3g

P.S. I use in Magento\Cms\Model\Page\Source\PageLayout::toOptionArray()
new code:

   $options[] = [
        'label' => 'TEST1',
        'value' => 'one',
    ];
    $options[] = [
        'label' => 'TEST2',
        'value' => 'two,three',
    ];

instead last:

    $options[] = [
        'label' => 'test',
        'value' => 'test, test',
    ];

Thanks for replying, but unfortunately you can not add any custom value to table and expect that it will work as you wish. The reason is that you can miss any steps that are required for valid new values assigning.

To be sure that your value will work correctly you should add it through the valid form (like create new attribute value or new tax class).

To be sure that there is no error with commas in drop-downs you can add your custom layout to the file \app\code\Magento\Theme\view\frontend\layouts.xml. After that you can change layout in cms page grid. Checkout my screenshots.

pic1

pic2

pic3

To get more information about layouts checkout our documentation http://devdocs.magento.com/guides/v2.1/frontend-dev-guide/bk-frontend-dev-guide.html

I used layout for example only...

Add to options array value with comma, for example: Magento\Cms\Model\Page\Source\PageLayout

You modified LABEL instead VALUE.
For layout column - "value" in the option array corresponding "layout id" in the layout.xml

Please, modify as below:

    <layout id="abc,abc">
        <label translate="true">TEST</label>
    </layout>

magento/module-cms/Model/Page/Source/PageLayout.php::toOptionArray() add:

var_dump($this->option);

Result:

  [4] =>
  array(2) {
    'label' =>
    string(4) "TEST"
    'value' =>
    string(7) "abc,abc"
  }
 

Layout ID with comma seems strange, but other fields value with comma are possible.

About validation:

In the CMS Page grid UI I don't see something like [0-9a-z], "alphanum", etc.

Here is the code from cms_page_listing:

<column name="page_layout">
            <argument name="data" xsi:type="array">
                <item name="options" xsi:type="object">Magento\Cms\Model\Page\Source\PageLayout</item>
                <item name="config" xsi:type="array">
                    <item name="filter" xsi:type="string">select</item>
                    <item name="component" xsi:type="string">Magento_Ui/js/grid/columns/select</item>
                    <item name="editor" xsi:type="string">select</item>
                    <item name="dataType" xsi:type="string">select</item>
                    <item name="label" xsi:type="string" translate="true">Layout</item>
                </item>
            </argument>
        </column>

xsi:type="string" everywhere.

And if value 'abc,abc' is invalid for grid, why can I see it in the grid popup?
https://www.diigo.com/item/image/4wouz/bnge
https://www.diigo.com/item/image/4wouz/y3px

You are right, I've found possible issue in js/grid/columns/select.js and created internal ticket (#MAGETWO-58380) for fix. This issue will be closed after fix.

Thanks and have a nice day!

Hi, I have encountered the same issue.
I was trying to add the Robots source to my column like this:

<column name="meta_robots">
   <argument name="data" xsi:type="array">
      <item name="options" xsi:type="object">Magento\Config\Model\Config\Source\Design\Robots</item>
         <item name="config" xsi:type="array">
         <item name="filter" xsi:type="string">select</item>
         <item name="component" xsi:type="string">Magento_Ui/js/grid/columns/select</item>
         <item name="editor" xsi:type="string">select</item>
         <item name="dataType" xsi:type="string">select</item>
         <item name="label" xsi:type="string" translate="true">Meta Robots</item>
         <item name="visible" xsi:type="boolean">false</item>
      </item>
   </argument>
</column>

but on the front the column is empty. It seems that the ui component can't match the values when there are comma.

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

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 14 days if no further activity occurs. Thank you for your contributions.

Don't stale :)

Was this page helpful?
0 / 5 - 0 ratings