Skip to content

Using an html form element as a root doesn't work #65

Closed
benekastah opened this Issue Dec 13, 2011 · 4 comments

3 participants

@benekastah

If I do this:

$('form').each(function () {
  var form = this,
      submit = $('button[type=submit]', form);
  submit.click(function () {
    // do stuff
  });
});

It doesn't work. The problem is that (at least in Chrome) html form elements have a length. Therefore, when qwery is trying to determine the root element, it looks at the form element as a qwery selector and returns form[0], which in this case turns out to be an input element of the form. The temporary way around this is to wrap the bare html form element in a qwery:

// instead of
var form = this;
// do 
var form = $(this);
@ded
Owner
ded commented Dec 13, 2011

this is a regression that i had solved for once a very, very long time ago... and i'm sure i never looped @rvagg into it. ironically this used to be an old bug in jQuery too where they weren't checking the fact that forms have length properties (gah, stupid DOM 0 feature).

@rvagg
Collaborator
rvagg commented Dec 13, 2011

Now that is interesting. Consider it assigned to me, I'll have a fix in shortly along with a test to make sure it stays fixed.

@rvagg rvagg added a commit that referenced this issue Dec 13, 2011
@rvagg rvagg use forms as contexts, closes #65 ca2e581
@rvagg
Collaborator
rvagg commented Dec 13, 2011

thanks for picking this up btw @benekastah

@ded ded pushed a commit that closed this issue Dec 13, 2011
@rvagg rvagg use forms as contexts, closes #65 ca2e581
@ded ded closed this in ca2e581 Dec 13, 2011
@ded ded closed this in 27c1f3f Dec 13, 2011
@benekastah

@rvagg No problem. That was fast!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.