-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Make sure the depends definition works for custom widgets. Also conve… #30570
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
Make sure the depends definition works for custom widgets. Also conve… #30570
Conversation
…rted code from PrototypeJS to jQuery.
Hi @hostep. Thank you for your contribution
❗ Automated tests can be triggered manually with an appropriate comment:
You can find more information about the builds here ℹ️ Please run only needed test builds instead of all when developing. Please run all test builds before sending your PR for review. For more details, please, review the Magento Contributor Guide documentation. 🕙 You can find the schedule on the Magento Community Calendar page. 📞 The triage of Pull Requests 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. 🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel ✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel |
@magento run all tests |
Seems like this could be covered only with the js unit test, but that would be too hard. Adding label "auto tests not required". Let's wait for test results. |
@magento run Functional Tests B2B, Functional Tests CE |
This pull request cannot be added to non-default project automatically. Please add it manually if needed. |
This pull request cannot be added to non-default project automatically. Please add it manually if needed. |
This pull request cannot be added to non-default project automatically. Please add it manually if needed. |
1 similar comment
This pull request cannot be added to non-default project automatically. Please add it manually if needed. |
Hi @ihor-sviziev, thank you for the review. |
This pull request cannot be added to non-default project automatically. Please add it manually if needed. |
This pull request cannot be added to non-default project automatically. Please add it manually if needed. |
1 similar comment
This pull request cannot be added to non-default project automatically. Please add it manually if needed. |
@sidolov @gabrieldagama what does this message from m2-backlog means? |
✔️ QA Passed Manual testing scenario:
<parameter name="test_select" xsi:type="select" visible="true" required="true" sort_order="10">
<label translate="true">Select</label>
<options>
<option name="val_1" value="val_1" selected="true">
<label translate="true">Value 1</label>
</option>
<option name="val_2" value="val_2">
<label translate="true">Value 2</label>
</option>
</options>
</parameter>
<parameter name="block_2_id" xsi:type="block" visible="true" required="true" sort_order="30">
<label translate="true">Block 2</label>
<depends>
<parameter name="test_select" value="val_2" />
</depends>
<block class="Magento\Cms\Block\Adminhtml\Block\Widget\Chooser">
<data>
<item name="button" xsi:type="array">
<item name="open" xsi:type="string" translate="true">Select Block...</item>
</item>
</data>
</block>
</parameter>
Before: ✖️ When we select the Value 1, CMS Chooser is visible After: ✔️ When I select the Value 1, CMS Chooser is not visible |
Hi @hostep , @ihor-sviziev there were some changes in the backlog app a few hours ago that caused such issue, it's resolved for now. Thank you for pointing out! |
Hi @hostep, thank you for your contribution! |
Hi @hostep <parameter name="reviews_to_display" xsi:type="block" visible="true" required="true" sort_order="20">
<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;
}
} |
@DmitryFurs: thanks for that! I was a bit afraid this ticket got accepted too quickly and it could potentially have some regressions. Sorry, I have very little experience with this backend form stuff, I only looked at the issue mentioned on #6868 and hoped QA would check the other hiding/showing stuff. |
@hostep and one more thing, when we use category chooser with required="true", the check is triggered even if the dependent field is hidden <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> |
@DmitryFurs As I understood - we need to revert changes from this PR? and later on prepare new PR that will cover all these cases? If so - could you please create PR for reverting? |
@ihor-sviziev I think this fix won't exactly make things worse, just does not cover all possible cases. If this fix is reverted, what is the probability that this problem will ever be fixed? |
Ah, ok, so in this case - could you report separate issue with additional cases? Thank you! |
@ihor-sviziev are these cases likely to be fixed in the next release? |
@DmitryFurs it doesn't seems like quite critical issue, so probably if someone from community will take it (maybe @hostep ?) - it will be fixed. |
Ah, good to hear this isn't a regression, phew! 🙂 As long as we don't run into these issues on projects of our own, I'm probably not going to spend more time on this, sorry! I hope someone else will be interested to look at this. |
…rted code from PrototypeJS to jQuery.
Description (*)
This fixes #6868 and basically implements the solution proposed on stackexchange.
The solution from stackexchange is a bit strange though, since they use jQuery while the original code used Prototype and this caused them to have to swap the following if around, since the headElement could either be a jQuery or Prototype element and it would crash if it was a jQuery object:
So instead of taking over the proposed code, I've converted all code touching
headElement
to now use jQuery so we no longer have this strange hybrid solution.Related Pull Requests
None
Fixed Issues (if relevant)
Manual testing scenarios (*)
Questions or comments
Before somebody asks, I'm not interested in writing tests for this, so if this is required, feel free to pick this up yourselves 🙂
Contribution checklist (*)