Widget Customizer: Dynamically-created inputs cause from to replace itself without event to trigger re-initialization
|Reported by:||westonruter||Owned by:||ocean90|
In the customizer, with every input/change event, a widget's fields get submitted via Ajax to the widget's update callback to obtain the updated widget instance (to pass along to the preview), and as part of this the widget's form callback is also executed and the new widget form is returned being populated with the sanitized instance. On the widgets admin page, there is a Save button which causes the widget form to get completely replaced with this sanitized widget form. But since in the customizer the form gets submitted with each user input, it cannot replace the form or else the user would continually lose their inputs if they enter them faster than the Ajax response returns.
When the Ajax response returns with the newly-sanitized widget form, we compare the existing widget form already loaded with the new widget form and check to verify that all of the same field elements are there, as if they are, then we can iterate over the original inputs in parallel with the sanitize inputs, and copy the state over from the sanitized input to the original input if sanitization caused it to be different (and if the user is not still focused in that field).
If, however, it finds that the input fields in the sanitized form do not match the current widget input fields, then the entire form is currently getting replaced (as it does on the widgets admin page).
There are two suggestions I have for how the above problems can be solved:
1) In the customizer, if there is a field mismatch between a sanitized form and the existing form, instead of replacing the form as on the widgets admin page, we should stop the live field updates and make the Apply button re-appear so that when this button is pressed, the form fields get disabled until the form is replaced with the new sanitized form.
2) We need to trigger an event when the widget form is updated so that any dynamically-generated fields can be re-initialized. Again, see #19675.
Also reported at:
Change History (24)
comment:1 @westonruter — 16 months ago
- Keywords has-patch added
- Owner set to ocean90
- Status changed from new to reviewing
- Summary changed from Widget Customizer: Dynamically-created inputs cause from to replace itself without event to trigger re-initailization to Widget Customizer: Dynamically-created inputs cause from to replace itself without event to trigger re-initialization