Skip to content

Commit

Permalink
Merge pull request #110 from david-davidson/use-jquery-find
Browse files Browse the repository at this point in the history
Use `$.find`, not `$.children`, to parse nested inputs within a specific form
  • Loading branch information
rhubarbselleven committed May 3, 2015
2 parents 0559800 + 71851d0 commit 815c355
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 815c355

Please sign in to comment.