Skip to content

Commit

Permalink
Use $.find, not $.children, to parse nested inputs within a
Browse files Browse the repository at this point in the history
specific form
  • Loading branch information
david-davidson authored and megawac committed Jul 15, 2015
1 parent 7452834 commit 11ab5e1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 18 additions & 0 deletions spec/javascripts/serialize.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,24 @@ describe('serializing a form', function() {
});
});

describe('when given a form element with nested inputs', function() {
beforeEach(function() {
this.form = $(
'<form>' +
'<div>' +
'<input type="text" name="foo" value="bar">' +
'</div>' +
'</form>'
)[0];

this.result = Backbone.Syphon.serialize(this.form);
});

it('retrieves the inputs\' values', function() {
expect(this.result.foo).to.equal('bar');
});
});

describe('when given more than 1 form', function() {
beforeEach(function() {
this.View = Backbone.View.extend({
Expand Down
2 changes: 1 addition & 1 deletion src/backbone.syphon.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ var getElementType = function(el) {
// Otherwise, get the form fields from the view.
var getForm = function(viewOrForm) {
if (_.isUndefined(viewOrForm.$el)) {
return $(viewOrForm).children(':input');
return $(viewOrForm).find(':input');
} else {
return viewOrForm.$(':input');
}
Expand Down

0 comments on commit 11ab5e1

Please sign in to comment.