backbone.modelbinding icon indicating copy to clipboard operation
backbone.modelbinding copied to clipboard

Adds support for checkbox arrays

Open kerinin opened this issue 13 years ago • 4 comments

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.

kerinin avatar Feb 24 '12 21:02 kerinin

+1

eddanger avatar Mar 27 '12 18:03 eddanger

using this in our project with no issues. please commit.

shine-on avatar Apr 18 '12 21:04 shine-on

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

sarxos avatar May 12 '12 17:05 sarxos

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'>

sarxos avatar May 12 '12 18:05 sarxos