Skip to content

Commit

Permalink
A Requred Validation Message is not cleared when a question becomes d…
Browse files Browse the repository at this point in the history
…isabled fix #7306 (#7315)
  • Loading branch information
andrewtelnov committed Nov 10, 2023
1 parent 11a2f08 commit 77423bf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1363,6 +1363,9 @@ export class Question extends SurveyElement<Question>
protected onReadOnlyChanged(): void {
this.setPropertyValue("isInputReadOnly", this.isInputReadOnly);
super.onReadOnlyChanged();
if(this.isReadOnly) {
this.clearErrors();
}
this.updateQuestionCss();
this.calcRenderedCommentPlaceholder();
}
Expand Down
19 changes: 18 additions & 1 deletion tests/surveyquestiontests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7621,4 +7621,21 @@ QUnit.test("QuestionHtmlModel hide some properties", function (assert) {
["hideNumber", "state", "titleLocation", "descriptionLocation", "errorLocation", "indent", "width"].forEach(property => {
assert.equal(Serializer.findProperty("html", property).visible, false, property + " should be hidden");
});
});
});
QUnit.test("Hide errors on making question disabled", function (assert) {
const survey = new SurveyModel({
elements: [
{ type: "text", name: "q1", inputType: "number" },
{ type: "text", name: "q2", isRequired: true, enableIf: "{q1} < 10" }
]
});
const q1 = survey.getQuestionByName("q1");
const q2 = survey.getQuestionByName("q2");
q1.value = 1;
q2.validate(true);
assert.equal(q2.isReadOnly, false, "q2 is enabled");
assert.equal(q2.errors.length, 1, "There is errors in the question");
q1.value = 100;
assert.equal(q2.isReadOnly, true, "q2 is read-only");
assert.equal(q2.errors.length, 0, "Clear errors on making questio read-only");
});

0 comments on commit 77423bf

Please sign in to comment.