Skip to content

Commit

Permalink
Merge branch 'gh-3294' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
evs-chris committed Feb 4, 2019
2 parents cb374fc + 1774347 commit 90a00c7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/view/items/element/binding/CheckboxNameBinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default class CheckboxNameBinding extends Binding {

handleChange() {
this.isChecked = this.element.node.checked;
this.group.value = this.model.get();
this.group.value = this.model.get().slice();
const value = this.element.getAttribute('value');
if (this.isChecked && !this.arrayContains(this.group.value, value)) {
this.group.value.push(value);
Expand Down
23 changes: 23 additions & 0 deletions tests/browser/twoway.js
Original file line number Diff line number Diff line change
Expand Up @@ -1711,4 +1711,27 @@ export default function() {
inputs = r.findAll('input');
t.ok(inputs[0].checked && !inputs[1].checked);
});

test('Old and new values should be set correctly with named checkbox bindings (#3293)', t => {
const ractive = new Ractive({
el: fixture,
template: `
<input type="checkbox" id="red" name="{{colors}}" value="red" />
<input type="checkbox" id="green" name="{{colors}}" value="green" /> `,
data: { colors: ['green'] }
});

ractive.observe(
'colors',
(newValue, oldValue) => {
t.deepEqual(newValue, ['green', 'red'], 'new value should be correct');
t.deepEqual(oldValue, ['green'], 'old value should be correct');
},
{
init: false
}
);

fire(ractive.find('#red'), 'click');
});
}

0 comments on commit 90a00c7

Please sign in to comment.