Skip to content

Commit

Permalink
Fixed surveyjs/private-tasks#274 - Boolean question's editing issue (#…
Browse files Browse the repository at this point in the history
…6793)

Co-authored-by: tsv2013 <[email protected]>
  • Loading branch information
tsv2013 and tsv2013 authored Aug 30, 2023
1 parent f27e327 commit f92c5da
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/question_boolean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class QuestionBooleanModel extends Question {
return this.value == this.getValueTrue();
}
public set booleanValue(val: any) {
if (this.isReadOnly) {
if (this.isReadOnly || this.isDesignMode) {
return;
}
this.setBooleanValue(val);
Expand Down Expand Up @@ -258,9 +258,8 @@ export class QuestionBooleanModel extends Question {
}
public onKeyDownCore(event: any): boolean {
if (event.key === "ArrowLeft" || event.key === "ArrowRight") {
preventDefaults(event);
event.stopPropagation();
this.calculateBooleanValueByEvent(event, event.key === "ArrowRight");
return;
}
return true;
}
Expand Down
46 changes: 46 additions & 0 deletions tests/questionBooleanTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,50 @@ QUnit.test("Check boolean labelRenderedAriaID", function (assert) {

question.titleLocation = "hidden";
assert.strictEqual(question.labelRenderedAriaID.indexOf("_ariaTitle") !== -1, true);
});

QUnit.test("Boolean shouldn't call preventDefault on key down", function (assert) {
var json = {
"elements": [
{
"type": "boolean",
"name": "bool",
}
]
};
var survey = new SurveyModel(json);
var question = <QuestionBooleanModel>survey.getAllQuestions()[0];

let pdCount = 0;
let spCount = 0;
const event = {
key: "ArrowLeft",
target: document.createElement("div"),
preventDefault: () => { pdCount++; },
stopPropagation: () => { spCount++; }
};
question.onKeyDownCore(event);
assert.equal(pdCount, 0);
assert.equal(spCount, 1);
});
QUnit.test("Boolean shouldn't set booleanValue in design time", function (assert) {
var json = {
"elements": [
{
"type": "boolean",
"name": "bool",
}
]
};
var survey = new SurveyModel(json);
var question = <QuestionBooleanModel>survey.getAllQuestions()[0];

assert.equal(question.value, undefined);

question.booleanValue = true;
assert.equal(question.value, true);

survey.setDesignMode(true);
question.booleanValue = false;
assert.equal(question.value, true);
});

0 comments on commit f92c5da

Please sign in to comment.