magento2: Widget parameter depends does not work correctly on specified block
Preconditions (*)
- Magento 2.4-develop
- PHP 7, MySQL: ANY
- 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 (*)
- Create a custom widget with widget.xml file
- 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]
{code}
1. Create a **custom input/textarea** with validation classes using a custom block
{code:xml}
[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]
{code}
{code:php}
[?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;
}
}
- Create new Widget
- Change depended select
- Press Save button
Expected result (*)
- When the chooser is hidden, the validation does not run on hidden nested inputs

- The input location and associated label should be hidden according to the dependency

Actual result (*)
-
Validation triggers on hidden nested input fields
Switch select to display chooser

-
Only the input field is hidden, the label remains visible

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”.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 16 (13 by maintainers)
Found 2 commits tagged with
MC-39096, just putting them here in case this is helpful: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: ✖️ Only the input field is hidden, the label remains visible
So, we will reopen the issue.
@DmitryFurs I’ll check it.
Additional case described in comment fixed in scope of internal code delivery of MC-39096.
Hi @DmitryFurs.
Thank you for your report and collaboration!
The related internal Jira ticket
MC-39096was closed asFixed.The fix will be available with the upcoming
2.4.3release.Hi @DmitryFurs.
Thank you for your report and collaboration!
The related internal Jira ticket
MC-39096was closed asFixed.The fix will be available with the upcoming
2.4.2release.