Skip to content
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
7 changes: 6 additions & 1 deletion backbone.modelbinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,12 @@ var modelbinding = (function(Backbone, _, $) {
var elementChange = function(ev){
var targetEl = view.$(ev.target);
var value = targetEl.val();
var text = targetEl.find(":selected").text();
var selections = targetEl.find(":selected");
if (selections.size() > 1) {
var text = _.map(selections, function(sel){ return sel.text });
} else {
var text = selections.text();
}
setModelValue(attribute_name, value, text);
};

Expand Down
4 changes: 4 additions & 0 deletions spec/javascripts/helpers/sample.backbone.app.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ AView = Backbone.View.extend({
<option value='pre_selected' selected='selected'>pre selected</option> \
<option value='not_selected'>not selected</option> \
</select> \
<select id='multiple_select' multiple='true'> \
<option value='selection_1'>Selection 1</option> \
<option value='selection_2'>Selection 2</option> \
</select> \
<input type='radio' id='graduated_yes' name='graduated' value='yes'>\
<input type='radio' id='graduated_no' name='graduated' value='no'>\
<input type='radio' id='graduated_maybe' name='graduated' value='maybe'>\
Expand Down
8 changes: 8 additions & 0 deletions spec/javascripts/selectboxConventionBindings.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ describe("select element convention binding", function(){

expect(this.model.get('education_text')).toEqual("i dun learned at grade skool");
});

it("applies the text of multiple selections to the model", function(){
var el = this.view.$("#multiple_select");
el.val(["selection_1", "selection_2"]);
el.trigger('change');

expect(this.model.get('multiple_select_text')).toEqual(["Selection 1", "Selection 2"]);
});

it("updates the model to the selected value when the model is set to a value that doesn't exist, on render", function(){
var el = this.view.$("#operating_system");
Expand Down