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

Adds support for checkbox arrays #71

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

kerinin
Copy link

@kerinin kerinin commented Feb 24, 2012

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.

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.
@eddanger
Copy link

+1

@shine-on
Copy link

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

@sarxos
Copy link

sarxos commented May 12, 2012

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
Copy link

sarxos commented May 12, 2012

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants