Skip to content

Commit

Permalink
Outside fields bug fix
Browse files Browse the repository at this point in the history
Resolves #461
In non-IE browsers outside fields are already included in elements
attribute of form, so there is no need to add outside fields again.
Courtesy of @FinesseRus
  • Loading branch information
kevindb committed Mar 7, 2017
1 parent 911efdf commit 76c7c90
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/jquery.form.js
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,8 @@
}

// #386; account for inputs outside the form which use the 'form' attribute
if ( formId ) {
// FinesseRus: in non-IE browsers outside fields are already included in form.elements.
if (formId && (semantic || /(Edge|Trident)\//.test(navigator.userAgent))) {
els2 = $(':input[form="' + formId + '"]').get(); // hat tip @thet
if ( els2.length ) {
els = (els || []).concat(els2);
Expand Down
6 changes: 6 additions & 0 deletions test/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@
<option selected="selected">MISSING_ATTR</option>
</select>
</div></form>

<!-- form8, outside fields -->
<form id="form8">
<input type="text" name="insideForm">
</form>
<input type="text" name="outsideForm" form="form8">
</div>


Expand Down
5 changes: 5 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,9 @@ describe('form', function() {
assert.strictEqual(a[i].value, expected[i].value, 'Value: ' + a[i].value + ' = ' + expected[i].value);
}
});

it('formToArray: outside fields', function() {
var formData = $('#form8').formToArray();
assert.strictEqual(formData.length, 2, 'There are two "successful" elements of the form');
});
});

0 comments on commit 76c7c90

Please sign in to comment.