Magento2: Widget parameter depends does not work correctly on specified block

Created on 28 Oct 2020  ·  13Comments  ·  Source: magento/magento2

Preconditions (*)

  1. Magento 2.4-develop
  2. PHP 7, MySQL: ANY
  3. Related issues / prs: https://github.com/magento/magento2/issues/6868 https://github.com/magento/magento2/issues/13316 https://github.com/magento/magento2/pull/30570

Steps to reproduce (*)

  1. Create a custom widget with widget.xml file
  2. Create required select option chooser
<parameter name="category_id" xsi:type="block" visible="true" required="true" sort_order="50">
    <label translate="true">Category</label>
    <depends>
        <parameter name="type" value="category" />
    </depends>
    <block class="Magento\Catalog\Block\Adminhtml\Category\Widget\Chooser">
        <data>
            <item name="button" xsi:type="array">
                <item name="open" xsi:type="string" translate="true">Select Category...</item>
            </item>
        </data>
    </block>
</parameter>
  1. Create a custom input/textarea with validation classes using a custom block
<parameter name="reviews_to_display" xsi:type="block" visible="true" required="true" sort_order="60">
    <label translate="true">Reviews to Display</label>
    <depends>
        <parameter name="type" value="category" />
    </depends>
    <block class="Vendor\Module\Block\Adminhtml\Widget\Parameter\Number" />
</parameter>
<?php

declare(strict_types=1);

namespace Vendor\Module\Block\Adminhtml\Widget\Parameter;

use Magento\Backend\Block\Template;
use Magento\Backend\Block\Template\Context;
use Magento\Framework\Data\Form\Element\AbstractElement;
use Magento\Framework\Data\Form\Element\Factory as ElementFactory;

class Number extends Template
{
    /**
     * @var ElementFactory
     */
    private $elementFactory;

    /**
     * @param Context $context
     * @param ElementFactory $elementFactory
     * @param array $data
     */
    public function __construct(
        Context $context,
        ElementFactory $elementFactory,
        array $data = []
    ) {
        $this->elementFactory = $elementFactory;
        parent::__construct($context, $data);
    }

    /**
     * @param AbstractElement $element
     *
     * @return AbstractElement
     */
    public function prepareElementHtml(AbstractElement $element)
    {
        $input = $this->elementFactory->create('text', ['data' => $element->getData()]);
        $input->setId($element->getId());
        $input->setForm($element->getForm());
        $input->setData('class', 'widget-option input-text admin__control-text');
        $input->addClass('validate-number')->addClass('validate-greater-than-zero');
        if ($element->getData('required')) {
            $input->addClass('required-entry');
        }

        $element->setData('after_element_html', $input->getElementHtml());
        $element->setData('value', null);

        return $element;
    }
}
  1. Create new Widget
  2. Change depended select
  3. Press Save button

Expected result (*)

  1. When the chooser is hidden, the validation does not run on hidden nested inputs
    image
  2. The input location and associated label should be hidden according to the dependency
    image

Actual result (*)

  1. Validation triggers on hidden nested input fields
    image
    Switch select to display chooser
    image
  1. Only the input field is hidden, the label remains visible
    image

Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.

  • [ ] Severity: S0 _- Affects critical data or functionality and leaves users without workaround._
  • [ ] Severity: S1 _- Affects critical data or functionality and forces users to employ a workaround._
  • [ ] Severity: S2 _- Affects non-critical data or functionality and forces users to employ a workaround._
  • [ ] Severity: S3 _- Affects non-critical data or functionality and does not force users to employ a workaround._
  • [ ] Severity: S4 _- Affects aesthetics, professional look and feel, “quality” or “usability”._
CatalogWidget Widget Confirmed P2 ready for dev Reported on 2.4.0 Reproduced on 2.4.x S2 Dev.Experience

Most helpful comment

Hi @DmitryFurs, @ihor-sviziev .

The issue, described in the comment https://github.com/magento/magento2/issues/30691#issuecomment-735590948, is still reproducible on fresh 2.4-develop.

Actual Result: :heavy_multiplication_x: Only the input field is hidden, the label remains visible

Peek 2020-12-14 09-33

So, we will reopen the issue.

All 13 comments

Hi @DmitryFurs. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, please, review the Magento Contributor Assistant documentation.

Please, add a comment to assign the issue: @magento I am working on this


  • Join Magento Community Engineering Slack and ask your questions in #github channel.

    :warning: According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

:clock10: You can find the schedule on the Magento Community Calendar page.

:telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket.

:movie_camera: You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

Hi @engcom-Alfa. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [ ] 5. Add label Issue: Confirmed once verification is complete.

  • [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.

The issue is reproducible on fresh 2.4-develop.

Actual Result: :heavy_multiplication_x:

Peek 2020-11-16 10-57

:white_check_mark: Confirmed by @engcom-Alfa
Thank you for verifying the issue. Based on the provided information internal tickets MC-39096 were created

Issue Available: @engcom-Alfa, _You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself._

Hi @DmitryFurs.

Thank you for your report and collaboration!

The related internal Jira ticket MC-39096 was closed as Fixed.

The fix will be available with the upcoming 2.4.2 release.

@magento-engcom-team @engcom-Alfa @sdzhepa Chooser validation now works correctly, but the dependent custom field still hides only the input, and the label remains visible.
image

Point 2 in Steps to Reproduce and point 2 in Actual Results

This can also be seen in the screenshot confirming the issue

The issue is reproducible on fresh 2.4-develop.

Actual Result: ✖️

Peek 2020-11-16 10-57

@magento-engcom-team @engcom-Alfa @zakdma @OlgaVasyltsun I think that the task is not done to the end, in the comments above there are details. can someone reopen the issue?

https://github.com/magento/magento2/commit/ec12bd86f29e32c0fe891ca46cd4c6d7a6a0fbe7
https://github.com/magento/magento2/commit/f1e5c457c922aad8f6b0d439a696c61d6dc018cc

@ihor-sviziev maybe you can help? There is no answer for a long time, but I would like this issue to be completely fixed in the next release. Or should I create a separate ticket?

Hi @engcom-Alfa. Thank you for working on this issue.
Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:


    1. Add/Edit Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

    1. Verify that the issue is reproducible on 2.4-develop branch
      Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
      - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
      - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!
    1. If the issue is not relevant or is not reproducible any more, feel free to close it.

@DmitryFurs I'll check it.

Hi @DmitryFurs, @ihor-sviziev .

The issue, described in the comment https://github.com/magento/magento2/issues/30691#issuecomment-735590948, is still reproducible on fresh 2.4-develop.

Actual Result: :heavy_multiplication_x: Only the input field is hidden, the label remains visible

Peek 2020-12-14 09-33

So, we will reopen the issue.

@engcom-Alfa the labels just disappeared. Could you add them back?

:white_check_mark: Confirmed by @ihor-sviziev
Thank you for verifying the issue. Based on the provided information internal tickets MC-39096 were created

Issue Available: @ihor-sviziev, _You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself._

Was this page helpful?
0 / 5 - 0 ratings