backbone.modelbinding
backbone.modelbinding copied to clipboard
Adds support for checkbox arrays
Checkboxes can now be given an identifier terminating
in []
to denote that the value attribute should be used
as an array key. For example, given the following form
<input type="checkbox" id="foo[]" value="bar"/>
<input type="checkbox" id="foo[]" value="baz" checked="checked"/>
the model binding would generate an array Model.foo = ['baz']
Setting the value to another array updates the checkbox states, so
Model.set('foo', ['bar'])
would produce
<input type="checkbox" id="foo[]" value="bar" checked="checked"/>
<input type="checkbox" id="foo[]" value="baz" />
in the view.
+1
using this in our project with no issues. please commit.
I integrated your solution in my fork since this project has been abandoned and this pull request probably never be merged. For Backbone.ModelBinding project continuation see:
https://github.com/oaprnd/backbone.modelbinding
Regards
Oh, and by the way - your change in sample.backbone.app.js breaks Jasmine tests performed on HtmlUnitDriver. That's because of the unnecessary comma in the HTML code:
<input type='checkbox' id='endorsements[]', value='class_b'>
Should be:
<input type='checkbox' id='endorsements[]' value='class_b'>