Ticket #2114 (closed bug: wontfix)
$(form.elements) fails in IE, selects only the form
| Reported by: | joern | Owned by: | |
|---|---|---|---|
| Priority: | major | Milestone: | 1.2.2 |
| Component: | core | Version: | 1.2.1 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
Though $([]).add(form.elements) works fine.
Attachments
Change History
comment:2 Changed 5 years ago by joern
Most likely caused by this optimization in init:
// Handle $(DOMElement)
if ( selector.nodeType ) {
this[0] = selector;
this.length = 1;
return this;
Can't figure out how to fix it.
comment:3 Changed 5 years ago by scott.gonzal
I added a patch which fixes the problem in IE, but this should probably be heavily tested with other selectors to make sure there are no unexpected side effects.
comment:4 Changed 5 years ago by joern
- Status changed from new to closed
- Resolution set to fixed
Fixed in [4436]. Thanks Scott for the patch.
comment:5 Changed 5 years ago by joern
- Status changed from closed to reopened
- Resolution fixed deleted
Reverted 4436, didn't work.
comment:6 Changed 5 years ago by scott.gonzal
I've added a new patch. This time I ran the test suite :-)
The idea is just to not use the optimization on forms (since that's what form.elements looks like in IE). I think the gained functionality outweighs the minor performance hit for $(document.forms[0]). This can also be tweaked to only prevent the optimization in IE.
comment:7 Changed 5 years ago by scott.gonzal
The new patch doesn't work either (well, it works in so far as the constructor now behaves the same as the add method). Trying to create this patch, I found a related bug that exists in all browsers:
$([]).add(form) behaves the same as $([]).add(form.elements).
comment:8 Changed 5 years ago by davidserduke
The problem appears to be that IE actually sticks the elements as array-like RIGHT IN THE FORM element. Then uses form.elements to link back to itself so
form.elements === form
Thus I'm not sure how to fix this since I can't see any way to tell which one the programmer passed in.
comment:9 Changed 5 years ago by brandon
- Status changed from reopened to closed
- Resolution set to wontfix
We've been able to fix this in the past ... with a very hacky mess which is probably why the fix isn't there anymore. As David mentioned form.elements === form in IE and there isn't a solid way to tell the difference.
A couple of workarounds:
$( $.makeArray(form.elements) ); $([]).add(form.elements);
comment:10 Changed 21 months ago by anonymous
Hi all,
$([]).add(form.elements) won't work in IE8, it just creates an jQuery Object with a length of 1 referring to form.elements.
That means, jQuery validate 1.6 with jQuery 1.6 may be broken in IE8 (always returns valid=true).
comment:11 Changed 20 months ago by steve.jstone@…
I had an issue where jquery.validate was failing in IE6, caused by the above error. I fixed this by updating line 446 and changed:
$([]).add(this.currentForm.elements).filter(":input")
to
$(':input',this.currentForm)
comment:12 Changed 8 months ago by andros
I managed to fix the issue by constructing myself the array used in the add() method:
var list = new Array();
for(var k=0;k<this.currentForm.elements.length;k++){
listeElements[k] = this.currentForm.elements[k];
}
$([]).add(listeElements).filter(":input")
Seems like the issue only appears in the add() method (currentForm.elements returns the form object), but it works fine when listing all elements in a loop.
comment:13 Changed 8 months ago by rwaldron
$("form:input")
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.


Testcase: [4352]