Bug Tracker

Ticket #11076 (closed bug: fixed)

Opened 3 years ago

Last modified 2 years ago

.clone(true) loses delegation filters

Reported by: jquery.com@… Owned by: dmethvin
Priority: high Milestone: 1.7.2
Component: event Version: 1.7.1
Keywords: Cc:
Blocking: Blocked by:

Description

When .delegate is set on a node, and the node or one of its ancestors is cloned with .clone(true), in jQuery 1.7 the delegate's object filter is not conserved and the delegate is transformed in a normal "click" event.

(in both test cases, top table is original and bottom table is cloned one)

1.6.4, correct behavior  http://jsfiddle.net/DFv8F/

  • clicking on "head" cell prints "row" in both tables
  • clicking on any "cell" cell prints "cell" in both tables
  • clicking on "last" cell prints "last" in both tables

1.7.1, incorrect behavior  http://jsfiddle.net/DFv8F/1/

  • first table (original) behaves as above
  • second table (clone) prints all of "last", "cell" and "row" when clicking on any of the table's cells.

note: adding a second true to .clone has no effect (and no reason to have any, since we're only losing metadata not the events themselves)

Change History

comment:1 Changed 3 years ago by dmethvin

  • Owner set to dmethvin
  • Priority changed from undecided to high
  • Status changed from new to assigned
  • Component changed from unfiled to event
  • Milestone changed from None to 1.7.2

Excellent test case and description, thanks! Yes, cloneCopyEvent() isn't setting the selector properly.

comment:2 Changed 3 years ago by Dave Methvin

  • Status changed from assigned to closed
  • Resolution set to fixed

Fix #11076. If .clone() won't delegate, we must remediate.

Since jQuery.event.add can accept a handleObj there's no need to reiterate them as args, but we *do* need to set the selector variable correctly.

Changeset: 633ca9c1610c49dbb780e565f4f1202e1fe20fae

Note: See TracTickets for help on using tickets.