Make WordPress Core

Opened 10 years ago

Last modified 6 years ago

#28747 new defect (bug)

$.wpColorPicker cannot duplicate elements

Reported by: kingyes's profile KingYes Owned by:
Milestone: 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
10 years ago

  • Focuses javascript added

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

#2 follow-up: @KingYes
10 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
10 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
10 years ago

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

Version 0, edited 10 years ago by KingYes (next)

#5 @chriscct7
9 years ago

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