WordPress.org

Make WordPress Core

Opened 4 years ago

Last modified 2 years ago

#28747 new defect (bug)

$.wpColorPicker cannot duplicate elements

Reported by: KingYes Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 3.9.1
Component: Widgets Keywords: needs-patch
Focuses: javascript Cc:

Description

I can't clone() wrap div when I use with wpColorPicker. If I just running the $.wpColorPicker method again, I see two instance about this.

What I can to do for duplicate?

Change History (5)

#1 @westonruter
4 years ago

  • Focuses javascript added

Please supply the PHP and JS code for the widget you are using.

#2 follow-up: @KingYes
4 years ago

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.

#3 in reply to: ↑ 2 @westonruter
4 years ago

Replying to 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();

#4 @KingYes
4 years ago

It's very hard to remove the color wrapper. Maybe WP need to add destroy method for this task?

Last edited 4 years ago by KingYes (previous) (diff)

#5 @chriscct7
2 years ago

  • Keywords needs-patch added
Note: See TracTickets for help on using tickets.