[wp-trac] [WordPress Trac] #28747: $.wpColorPicker cannot duplicate elements

WordPress Trac noreply at wordpress.org
Mon Jul 7 05:39:36 UTC 2014


#28747: $.wpColorPicker cannot duplicate elements
--------------------------+------------------------------
 Reporter:  KingYes       |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Widgets       |     Version:  3.9.1
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:  javascript
--------------------------+------------------------------

Comment (by westonruter):

 Replying to [comment:2 KingYes]:
 > hey @westonruter.
 >
 > When I just create a new instance for wpColorPicker like this: `$( 'my-
 selector' ).wpColorPicker();`, and I duplicate this div with `$.clone()`
 method. But with new html, the picker not works. So when I running `$(
 'my-new-selector' ).wpColorPicker();` again, I see two instance of the
 color picker.
 >
 > Do you understand what I say?
 >
 > Thanks,
 > Yakir.


 I think I understand. I think the problem is that using jQuery `clone` is
 not copying the attached event handlers and `data` attributes. So what I
 would recommend doing is upon cloning the container, that you then remove
 the color picker that was cloned and then re-initialize the color-picker
 on that element via `$( clonedElement ).find( 'my-slector'
 ).wpColorPicker()`;

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


More information about the wp-trac mailing list