Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reject disabled fields #99

Open
wants to merge 4 commits into
base: major
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,8 @@ For more information on Key Assignment Validators, see the full

## Current Limitations

There some known limitations in Backbone.Syphon, partially by design and
partially implemented as default behaivors.
There are some known limitations in Backbone.Syphon, partially by design and
partially implemented as default behavior.

* You must have a `<form>` within your view's `$el`
* An input of type `checkbox` will return a boolean value. This can be
Expand Down
52 changes: 52 additions & 0 deletions spec/javascripts/serialize.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,4 +269,56 @@ describe('serializing a form', function() {
expect(this.result.foo).to.equal('bar');
});
});

describe("when serializing forms with disabled text fields", function(){
var View = Backbone.View.extend({
render: function(){
this.$el.html("<form><input type='text' name='foo' value='bar'><input type='text' name='ignore' value='bar' disabled></form>");
}
});

var view, result;

beforeEach(function(){
view = new View();
view.render();

result = Backbone.Syphon.serialize(view);
});

it("should return an object with a key from the text input name, and ignore disabled", function(){
expect(result.hasOwnProperty("foo")).toBe(true)
expect(result.hasOwnProperty("ignore")).toBe(false)
});

it("should have the input's value", function(){
expect(result.foo).toBe("bar");
});
});

describe("when serializing forms with disabled select field", function(){
var View = Backbone.View.extend({
render: function(){
this.$el.html("<form><input type='text' name='foo' value='bar'><select name='ignore' disabled='disabled'><option selected='selected' value='bar'>bar</option><option value='bar2'>bar2</option></select></form>");
}
});

var view, result;

beforeEach(function(){
view = new View();
view.render();

result = Backbone.Syphon.serialize(view);
});

it("should return an object with a key from the text input name, and ignore disabled", function(){
expect(result.hasOwnProperty("foo")).toBe(true)
expect(result.hasOwnProperty("ignore")).toBe(false)
});

it("should have the input's value", function(){
expect(result.foo).toBe("bar");
});
});
});
3 changes: 3 additions & 0 deletions src/backbone.syphon.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ var getInputElements = function(view, config){
var elements = form.elements;

elements = _.reject(elements, function(el){
// Reject disabled fields always
if (el.hasAttribute('disabled')) { return true; }

var reject;
var type = getElementType(el);
var extractor = config.keyExtractors.get(type);
Expand Down