Bug Tracker

Opened 8 years ago

Closed 8 years ago

#14678 closed bug (invalid)

$(element).closest('FORM') sometimes returns an array instead of the form element

Reported by: [email protected] Owned by: [email protected]
Priority: undecided Milestone: None
Component: unfiled Version: 1.9.1
Keywords: Cc:
Blocked by: Blocking:


This is different from #11738 ...

I am generating a large number of forms programmatically using templates (PHP Cake). For each text and textarea there is a select dropdown with a list of tags, and when the dropdown is operated, the onChange event calls a small JS function of my own which appends the tag to the input control's content.

<select onChange="add_tag('caption_3',this);" ... >

The function uses JQuery to locate the adjacent input control and do the append, like this:

function add_tag(target, select) {

   // jQuery bug
   var form = $(select).closest('FORM');
   if ($.isArray(form)) {
      form = form[0];
      console.log(target + ' got an array');
   elem = $(form).find('[name=' + target + ']')[0];
   if (elem.nodeName == 'TEXTAREA')
      elem.innerHTML += select.value;
      elem.value += select.value;

As the code implies, I sometimes but rarely get an array returned by closest() rather than a direct reference to the element. I have been unable to figure out exactly what circumstances trigger this problem.

Change History (2)

comment:1 Changed 8 years ago by dmethvin

Owner: set to [email protected]
Status: newpending

If i had to guess I'd say it's a domlint issue. Since there's no test case I'll just leave it at a guess. If you can put together something in jsfiddle.net and let us know how it fares on various browsers we could see if it's really a jQuery bug.

comment:2 Changed 8 years ago by trac-o-bot

Resolution: invalid
Status: pendingclosed

Because we get so many tickets, we often need to return them to the initial reporter for more information. If that person does not reply within 14 days, the ticket will automatically be closed, and that has happened in this case. If you still are interested in pursuing this issue, feel free to add a comment with the requested information and we will be happy to reopen the ticket if it is still valid. Thanks!

Note: See TracTickets for help on using tickets.