Skip to main content

Bug Tracker

Side navigation

#14678 closed bug (invalid)

Opened January 09, 2014 01:28AM UTC

Closed January 23, 2014 08:53AM UTC

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

Reported by: dcrooke@gmail.com Owned by: dcrooke@gmail.com
Priority: undecided Milestone: None
Component: unfiled Version: 1.9.1
Keywords: Cc:
Blocked by: Blocking:
Description

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;
   else
      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.

Attachments (0)
Change History (2)

Changed January 09, 2014 01:43AM UTC by dmethvin comment:1

owner: → dcrooke@gmail.com
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.

Changed January 23, 2014 08:53AM UTC by trac-o-bot comment:2

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!