[wp-trac] [WordPress Trac] #27491: Widget Customizer: Dynamically-created inputs cause from to replace itself without event to trigger re-initialization

WordPress Trac noreply at wordpress.org
Sun Mar 30 07:08:50 UTC 2014


#27491: Widget Customizer: Dynamically-created inputs cause from to replace itself
without event to trigger re-initialization
--------------------------+-------------------------
 Reporter:  westonruter   |       Owner:  ocean90
     Type:  defect (bug)  |      Status:  reviewing
 Priority:  normal        |   Milestone:  3.9
Component:  Widgets       |     Version:  trunk
 Severity:  normal        |  Resolution:
 Keywords:  has-patch     |     Focuses:  javascript
--------------------------+-------------------------

Comment (by westonruter):

 I got stuck down a rabbit hole of trying to improve the way that widgets
 get cloned from their templates so that events and data attached to the
 widget templates would be persisted via a deep copy when the widget was
 added to a widget area: https://github.com/x-team/wordpress-
 develop/commit/542ad8f342afee43feab8f8017bac755cbfacf90

 But I found that a widget with a jQuery UI control failed when deep
 cloning just as a widget with Chosen in it. So I abandoned that path.
 However, in the future the way that widget controls get instantiated
 should really start out with a widget template not pulled from a hidden
 DOM element, but instead pull from a template string that is re-parsed
 each time. What widgets now do to manipulate the widget templates upon DOM
 ready (e.g. Jetpack's Widget Visibility), they should instead transition
 to do in a `widget-added` event. Widget controls at the moment are not
 just accommodating to dynamic behaviors, as they have been largely static
 HTML forms. This needs to change in the future. Widgets should be
 completely overhauled to use Backbone.

 So, I updated the example widget to use the `widget-updated` and `widget-
 added` events, which in the latter case cleans up any inert Chosen field
 copied during the shallow clone, and re-initializes the Chosen select:
 https://gist.github.com/westonruter/9676069

--
Ticket URL: <https://core.trac.wordpress.org/ticket/27491#comment:10>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list