Nice to know someone read my post!

The problem is that clone() clones the DOM element (the DIV), not the
widget object, so the click handlers for $('#experiment1')  and $
('#experiment2') (which was copied from $('#experiment1'); that's what
clone(true) does) both refer to the same function object, function()
{ self.move() } where self is bound to the superbox widget object
(only one of which exists!), and self.element refers to $
('experiment1'). Notice that when you click $('#experiment2'), it's $
('#experiment1') that moves.

You need a whole new widget on the cloned element. Try $
('#experiment1').clone().superbox() (note, not clone(true)! You don't
want to call the original click handler)

There's no way with the current code for clone() to create a new
widget; the element doesn't know that there are any widget objects
attached. They are available with $('experiment1').data('superbox'),
but data() is used for lots of things; no way to know that in this
case it's a UI widget. So just call the widget creator after clone().

Danny

On Jan 9, 5:01 pm, jayg <[email protected]> wrote:
> Scott, sorry for the delayed response, had to come up with a stripped
> down test page and find somewhere to put it.  I have used for my
> example, I used the superbox 
> onhttp://youngisrael-stl.org/wordpress/2008/08/22/extending-jquery-ui-w...
> The example page can be found 
> here:http://sarahhealydesign.com/widget_test.html
>
> What I am trying to do seems like it should be simple, and perhaps I
> am missing something obvious.  Basically all I do is attach a click to
> the button, and do:
> $('#experiment1')
>            .clone(true)
>            .appendTo('body')
>            .attr('id','experiment2');
>
> I attached an alert to the superbox, so whenever you click it, it
> tells you what it thinks is its id with this.element.get(0).id
>
> You will see in the example that it always returns experiment1 for the
> id.  Any help is much appeciated!
>
> -j
>
> On Jan 8, 11:20 am, Scott González <[email protected]> wrote:
>
> > Can you provide a demo page showing your problem?
>
> > On Jan 7, 10:20 pm, jayg <[email protected]> wrote:
>
> > > I have a custom widget built on jquery UI that I am running into an
> > > odd issue with.  Everything works as I want on initial use, but when I
> > > do a clone(true) on the widget and append it to another element, the
> > > cloned version does not seem to have a proper handle on where it lives
> > > in the dom - it returns the old id upon calling this.element.get
> > > (0).id.  Do I need to do something, maybe call some method, to update
> > > this information w/in the widget, or is this only ever set upon
> > > initial creation?  I did try calling $('#myItem').myWidget('init'),
> > > but no dice.  Any thoughts?  Something obvious I am missing?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery UI" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/jquery-ui?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to