Skip to content

Commit

Permalink
bugfix: double click on checkbox cell should invert the value
Browse files Browse the repository at this point in the history
  • Loading branch information
warpech committed Nov 20, 2013
1 parent f40525d commit 1c7a93a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1574,8 +1574,8 @@ Handsontable.Core = function (rootElement, userSettings) {
* @return {Object|undefined} ending td in pasted area (only if any cell was changed)
*/
this.populateFromArray = function (row, col, input, endRow, endCol, source, method) {
if (typeof input !== 'object') {
throw new Error("populateFromArray parameter `input` must be an array"); //API changed in 0.9-beta2, let's check if you use it correctly
if (!(typeof input === 'object' && typeof input[0] === 'object')) {
throw new Error("populateFromArray parameter `input` must be an array of arrays"); //API changed in 0.9-beta2, let's check if you use it correctly
}
return grid.populateFromArray({row: row, col: col}, input, typeof endRow === 'number' ? {row: endRow, col: endCol} : null, source, method);
};
Expand Down
6 changes: 5 additions & 1 deletion src/editors/checkboxEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
//Blank editor, because all the work is done by renderer
var CheckboxEditor = Handsontable.editors.BaseEditor.prototype.extend();

CheckboxEditor.prototype.beginEditing = function () {};
CheckboxEditor.prototype.beginEditing = function () {
this.saveValue([
[!this.originalValue]
]);
};
CheckboxEditor.prototype.finishEditing = function () {};

CheckboxEditor.prototype.init = function () {};
Expand Down
22 changes: 22 additions & 0 deletions test/jasmine/spec/renderers/checkboxRendererSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,26 @@ describe('CheckboxRenderer', function () {

});

it("double click on checkbox cell should invert the value", function () {
handsontable({
data: [
[true],
[false],
[true]
],
columns: [
{ type: 'checkbox'}
]
});

mouseDoubleClick($(getCell(0, 0)));
expect(getDataAtCell(0, 0)).toBe(false);

mouseDoubleClick($(getCell(0, 0)));
expect(getDataAtCell(0, 0)).toBe(true);

mouseDoubleClick($(getCell(0, 0)));
expect(getDataAtCell(0, 0)).toBe(false);
});

});

0 comments on commit 1c7a93a

Please sign in to comment.