Ticket #3803 (closed feature: patcheswelcome)

Opened 6 years ago

Last modified 22 months ago

Feature request: cloning widgets

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

Description

Per this thread  http://groups.google.com/group/jquery-ui/browse_thread/thread/a1cbbd784aa0dae2, 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
    .each(function(){
      var handlers = $.data(this,'events')[ 'cloneTheWidgets'];
      if (handlers) for (var handler in handlers)
        // manually trigger the clone event handlers
        handlers[handler].apply(this);
    });
};

and in the widget init function:

init: function(){
  var self = this;
  self.element.bind('cloneTheWidgets', function() {
    $(this)[self.widgetName](self.options);
  });
  ...the rest of your init
} 

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

Change History

comment:1 Changed 5 years ago by joern.zaefferer

  • Milestone changed from TBD to 1.next

comment:2 Changed 4 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: ↓ 5 Changed 4 years ago by joern.zaefferer

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

comment:4 Changed 4 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 4 years ago by scott.gonzalez

  • Component changed from ui.core to ui.widget
  • Milestone changed from 1.next 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 2 years ago by joern.zaefferer

  • Status changed from new to open

comment:7 Changed 22 months ago by scott.gonzalez

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

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 22 months ago by scott.gonzalez

  • Milestone TBD deleted

Milestone TBD deleted

Note: See TracTickets for help on using tickets.