-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Widget-id value used to build form field ids isn't consistent with hidden widget-id field #28668
Comments
Following @noisysocks 's merge of the updates to the REST API widget endpoints in #29649 it's still the case that we get a bad value like However it seems that when we add the widget in the old editor, the hidden inputs in the new editor are correct and the names of the form fields are also correct. Also inspecting the save widget call the response features a correct Debugging this I noticed that the correct number is used for everything if the widget is having any form field edited. E.g.
@noisysocks is this something that can be addressed as part of the refresh of the Legacy Widget block in #29960 ? |
I believe that this issue remains even after #29960 although all of the IDs now use It's a little tricky to solve this because we don't know what the correct number is until the widget is saved which, in the new screen, happens after the widget is added. Still, maybe we can "guess" what the number will be. |
Hello @noisysocks, what do you mean ? Or we need the PR #29960 will be merged to test again ? Thanks |
How does the customizer work? I can add widgets there and they get the correct number and the form fields are correct without the widgets being saved or published. Can't we do something similar? |
@manooweb: What I mean is that this bug still exists 🙂 It's in the backlog waiting for a developer to pick up. @draganescu: That's a good question. The Customizer can serve as inspiration here. |
I would like but I was still busy with our code in our side. In addition as I said before I need some guidance to correctly understand how the part of Gutenberg code works to save time especially first where to look for to show how the widget_id is managed in the legacy widget block UI. Thanks. |
I created a github repository with a complete example to make the issue easier to test I could start to explore Gutenberg code. |
🤔 My example works fine with Gutenberg 10.3.2 but not with the trunk.
So the script can't find anymore the checkbox fields because there are based on the Is there something I missed ? Is there something has been changed since the 10.3.x release ? |
I think we've lost something since the #29960 iteration |
This PR #30709 fixes the issue of hidden widget fields. However a new issue appears now. Steps to reproduce
Screenshot of the code in the old screenScreenshot of the code in the new screen |
Thanks for testing @manooweb. I'll work on a fix shortly. |
Hi, I see this issue is closed. But I also noticed the difference in id from the hidden formfield when editing the widget compared to the id seen when actually rendering the widget. Any feedback or update on this? Thanks in advance! |
I still have the same problem in WordPress 6.1 - the filter gives me |
Description
When I add our legacy widget as a new legacy widget in any widget area its form field ids and names are based on the WP_Widget::$id_base and WP_Widget::$number used by calling WP_Wigdet::get_field_id() or WP_Widget::get_field_name() method or directly using the WP_Widget::$id property.
See https://github.com/polylang/polylang/blob/master/include/widget-languages.php#L102-L137
In the new widget screen, for our legacy widget fields I obtained something like that:
Notice the
--1
for the id andwidget-polylang[-1][dropdown]
for the name of the field in the code above.The new widget screen also adds some hidden fields for each widget. The rendering is the responsability of the LegacyWidgetEditDomManager component
See https://github.com/WordPress/gutenberg/blob/v9.8.3/packages/edit-widgets/src/blocks/legacy-widget/edit/dom-manager.js#L100-L131
At the end when the widget is added into the widget area these fields are;
Notice that the
widget-id
andwidget_number
fields aren't consistent with ones are used in the widget form fields.This issue creates another one on our side because we have some js code which manipulate the fields to prevent the user to make wrong choice.
Step-by-step reproduction instructions
Inspect
id
andname
attribute of theinput
tagExpected behaviour
Exactly the same as the legacy widget screen
wp-admin/widgets.php
Each field need to be consistent with the widget
id_base
andnumber
properties.For example in the old screen:
and
Going further
One part of the issue is due to the REST API controller which retrieves the legacy widget to add it in the widget area.
See https://github.com/WordPress/gutenberg/blob/v9.8.3/lib/class-wp-rest-widget-types-controller.php#L408
Notice I've not debugged the React part of the issue yet especially on how the widget
id_base
andnumber/instance
props is retrieved.However I can surely say that it is what creates an issue in our legacy widget. Indeed I modified manually the HTML code in the browser and clicked on its options. All worked as expected including the correct refreshing of the React component. Save the widgets screen by clicking the
Udpate
button also works fine. I can verify by using the legacy widget screen.It seems there is no problem to manipulate the widget fields with javascript code due to the
LegacyWidgetEditHandler
component implementation which listen any changes in the widget form, if I understood well.WordPress information
Device information
The text was updated successfully, but these errors were encountered: