Open
Conversation
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'> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Checkboxes can now be given an identifier terminating
in
[]to denote that the value attribute should be usedas an array key. For example, given the following form
the model binding would generate an array
Model.foo = ['baz']Setting the value to another array updates the checkbox states, so
would produce
in the view.