Opened 8 years ago

Closed 4 years ago

Last modified 4 years ago

#3803 closed feature (patcheswelcome)

Feature request: cloning widgets

Reported by: d.wachss Owned by:
Priority: minor Milestone:
Component: ui.widget Version: 1.6rc4
Keywords: Cc:
Blocked by: Blocking:


Per this thread, clone() does not clone the widgets associated with an element. One way to do this is with a custom event:

$.fn.cloneTheWidgets = function (){
  return this.clone() // don't clone events
      var handlers = $.data(this,'events')[ 'cloneTheWidgets'];
      if (handlers) for (var handler in handlers)
        // manually trigger the clone event handlers

and in the widget init function:

init: function(){
  var self = this;
  self.element.bind('cloneTheWidgets', function() {
  ...the rest of your init

or override the native clone() to do this with some appropriate argument.

Change History (8)

comment:1 Changed 8 years ago by jzaefferer

  • Milestone changed from TBD to

comment:2 Changed 7 years ago by nxtwrld

i would suggest this behavior for 'clone':

clone(true) - automatically reinitialize the widget in the cloned DOM clone() - cleanup the widget in the cloned DOM

comment:3 follow-up: Changed 6 years ago by jzaefferer

Do we actually want to support cloning widgets? Still seems like a rather niche usecase.

comment:4 Changed 6 years ago by nxtwrld

Now it seems pretty inconsistent, as clone will result in cloning all the helper elements created by the widget, so you end up with a code, where widget does not work, but you can not reinitialize it again, as the original DOM has been cloned already in modified state.

comment:5 in reply to: ↑ 3 Changed 6 years ago by scottgonzalez

  • Component changed from ui.core to ui.widget
  • Milestone changed from to TBD

Replying to joern.zaefferer:

Do we actually want to support cloning widgets? Still seems like a rather niche usecase.

We haven't made a decision, and likely won't make a decision for a while. Until we do, we're leaving the ticket open. If anyone has ideas for how to make this actually work, we'd be interested in hearing them. Unfortunately this is probably way too widget-specific to be generalized.

comment:6 Changed 5 years ago by jzaefferer

  • Status changed from new to open

comment:7 Changed 4 years ago by scottgonzalez

  • Resolution set to patcheswelcome
  • Status changed from open to closed

If anyone has an idea for how to accomplish this, please discuss it with the team. But for now it seems like there would need to be too much widget-specific code to handle a uncommon case.

comment:8 Changed 4 years ago by scottgonzalez

  • Milestone TBD deleted

Milestone TBD deleted

Note: See TracTickets for help on using tickets.