Skip to content

Commit

Permalink
Allow to have undefined values #8470
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov committed Jul 1, 2024
1 parent ae7a833 commit ce5ff2d
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/jsonobject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ export class JsonObjectProperty implements IObject, IJsonPropertyInfo {
}
if(this.isLocalizable) return value === null || value === undefined;
return (
(value === false && (this.type == "boolean" || this.type == "switch")) ||
(value === false && (this.type == "boolean" || this.type == "switch") && !this.defaultValueFunc) ||
value === "" || Helpers.isValueEmpty(value)
);
}
Expand Down
33 changes: 21 additions & 12 deletions src/question_comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,36 @@ export class QuestionCommentModel extends QuestionTextBase {
* Default value: `false` (inherited from `SurveyModel`'s [`autoGrowComment`](https://surveyjs.io/form-library/documentation/surveymodel#autoGrowComment) property)
* @see allowResize
*/
public get autoGrow(): boolean {
return this.getPropertyValue("autoGrow") || (this.survey && this.survey.autoGrowComment);
public get autoGrow(): boolean | undefined {
return this.getPropertyValueWithoutDefault("autoGrow");
}
public set autoGrow(val: boolean) {
this.setPropertyValue("autoGrow", val);
public set autoGrow(val: boolean | undefined) {
if(val !== this.autoGrow) {
this.setPropertyValueDirectly("autoGrow", val);
}
}
public get renderedAutoGrow(): boolean {
const autoGrow = this.autoGrow;
return autoGrow === undefined && this.survey ? this.survey.autoGrowComment : !!autoGrow;
}
/**
* Specifies whether to display a resize handle for the comment area.
*
* Default value: `true` (inherited from `SurveyModel`'s [`allowResizeComment`](https://surveyjs.io/form-library/documentation/surveymodel#allowResizeComment) property)
* @see autoGrow
*/
public get allowResize(): boolean {
const value = this.getPropertyValue("allowResize");
return value === null ? (this.survey && this.survey.allowResizeComment) : value;
public get allowResize(): boolean | undefined {
return this.getPropertyValueWithoutDefault("allowResize");
}
public set allowResize(val: boolean) {
this.setPropertyValue("allowResize", val);
public set allowResize(val: boolean | undefined) {
if(val !== this.allowResize) {
this.setPropertyValueDirectly("allowResize", val);
}
}
public get renderedAllowResize(): boolean {
return this.allowResize && !this.isPreviewStyle && !this.isReadOnlyStyle;
const res = this.allowResize;
const allowResize = res === undefined && this.survey ? this.survey.allowResizeComment : !!res;
return allowResize && !this.isPreviewStyle && !this.isReadOnlyStyle;
}
public get resizeStyle() {
return this.renderedAllowResize ? "both" : "none";
Expand Down Expand Up @@ -139,8 +148,8 @@ Serializer.addClass(
default: "default",
choices: ["default", "onBlur", "onTyping"],
},
{ name: "autoGrow:boolean", default: null },
{ name: "allowResize:boolean", default: null },
{ name: "autoGrow:boolean", defaultFunc: () => undefined },
{ name: "allowResize:boolean", defaultFunc: () => undefined },
{ name: "acceptCarriageReturn:boolean", default: true, visible: false }
],
function () {
Expand Down
80 changes: 56 additions & 24 deletions tests/surveytests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15025,7 +15025,7 @@ QUnit.test("onElementWrapperComponentName event", function (assert) {
QUnit.test("onElementWrapperComponentName event", function (assert) {
const survey = new SurveyModel({
elements: [{ type: "text", name: "q1" }, { type: "checkbox", name: "q2", choices: [1, 2] },
{ type: "matrixdynamic", name: "q3", rowCount: 1, columns: [{ name: "col1" }] }
{ type: "matrixdynamic", name: "q3", rowCount: 1, columns: [{ name: "col1" }] }
]
});
const q1 = survey.getQuestionByName("q1");
Expand Down Expand Up @@ -15476,18 +15476,42 @@ QUnit.test("survey.autoGrowComment", function (assert) {
]
};
let survey = new SurveyModel(json);
let comment1 = survey.getQuestionByName("comment1");
let comment2 = survey.getQuestionByName("comment2");
let comment1 = survey.getQuestionByName("comment1") as QuestionCommentModel;
let comment2 = survey.getQuestionByName("comment2") as QuestionCommentModel;

assert.equal(survey.autoGrowComment, true);
assert.equal(comment1.autoGrow, true);
assert.equal(comment2.autoGrow, true);
assert.equal(survey.autoGrowComment, true, "#1");
assert.equal(comment1.renderedAutoGrow, true, "#2");
assert.equal(comment2.renderedAutoGrow, true, "#3");

survey.autoGrowComment = false;
assert.equal(comment1.autoGrow, false);
assert.equal(comment2.autoGrow, true);
assert.equal(comment1.renderedAutoGrow, false, "#4");
assert.equal(comment2.renderedAutoGrow, true, "#5");
});
QUnit.only("survey.allowResizeComment", function (assert) {
QUnit.test("save comment autoGrow && autoResize", function (assert) {
let json = {
autoGrowComment: true,
pages: [
{
elements: [
{
type: "comment",
name: "q1",
}
]
}
]
};
let survey = new SurveyModel(json);
let question = survey.getQuestionByName("q1") as QuestionCommentModel;
assert.deepEqual(question.toJSON(), { name: "q1" }, "#1");
question.allowResize = false;
question.autoGrow = false;
assert.deepEqual(question.toJSON(), { name: "q1", allowResize: false, autoGrow: false }, "#2");
question.allowResize = true;
question.autoGrow = true;
assert.deepEqual(question.toJSON(), { name: "q1", allowResize: true, autoGrow: true }, "#3");
});
QUnit.test("survey.allowResizeComment", function (assert) {
let json = {
allowResizeComment: false,
pages: [
Expand All @@ -15511,23 +15535,23 @@ QUnit.only("survey.allowResizeComment", function (assert) {
let comment2 = survey.getQuestionByName("comment2") as QuestionCommentModel;

assert.equal(survey.allowResizeComment, false);
assert.equal(comment1.renderedAllowResize, false, "comment1 survey.allowResizeComment = false");
assert.equal(comment2.renderedAllowResize, false, "comment2 survey.allowResizeComment = false");
assert.equal(comment1.renderedAllowResize, false, "comment1 survey.allowResizeComment = false, #1");
assert.equal(comment2.renderedAllowResize, false, "comment2 survey.allowResizeComment = false, #2");

survey.allowResizeComment = true;
assert.equal(comment1.renderedAllowResize, true, "comment1 survey.allowResizeComment = true");
assert.equal(comment2.renderedAllowResize, false, "comment2 survey.allowResizeComment = true");
assert.equal(comment1.renderedAllowResize, true, "comment1 survey.allowResizeComment = true, #3");
assert.equal(comment2.renderedAllowResize, false, "comment2 survey.allowResizeComment = true, #4");

comment1.readOnly = true;
assert.equal(comment1.renderedAllowResize, false);
assert.equal(comment1.renderedAllowResize, false, "#5");
comment1.readOnly = false;

survey.showPreview();
let comment1Preview = survey.getQuestionByName("comment1");
assert.equal(comment1Preview.renderedAllowResize, false);
assert.equal(comment1Preview.renderedAllowResize, false, "#6");
});

QUnit.only("survey.allowResizeComment & survey.autoGrowComment override this properties for individual properties", function (assert) {
QUnit.test("survey.allowResizeComment & survey.autoGrowComment override this properties for individual properties", function (assert) {
let json = {
allowResizeComment: false,
autoGrowComment: false,
Expand All @@ -15543,6 +15567,11 @@ QUnit.only("survey.allowResizeComment & survey.autoGrowComment override this pro
{
type: "comment",
name: "comment2",
},
{
type: "comment",
name: "comment3",
autoGrow: false
}
]
}
Expand All @@ -15551,18 +15580,21 @@ QUnit.only("survey.allowResizeComment & survey.autoGrowComment override this pro
let survey = new SurveyModel(json);
let comment1 = survey.getQuestionByName("comment1") as QuestionCommentModel;
let comment2 = survey.getQuestionByName("comment2") as QuestionCommentModel;
let comment3 = survey.getQuestionByName("comment3") as QuestionCommentModel;

assert.equal(comment1.renderedAllowResize, true, "comment1 survey.allowResizeComment = false");
assert.equal(comment1.autoGrow, true, "comment1 survey.autoGrowComment = false");
assert.equal(comment2.renderedAllowResize, false, "comment2 survey.allowResizeComment = false");
assert.equal(comment2.autoGrow, false, "comment2 survey.autoGrowComment = false");
assert.equal(comment1.renderedAllowResize, true, "comment1 survey.allowResizeComment = false, #1");
assert.equal(comment1.renderedAutoGrow, true, "comment1 survey.autoGrowComment = false, #2");
assert.equal(comment2.renderedAllowResize, false, "comment2 survey.allowResizeComment = false, #3");
assert.equal(comment2.renderedAutoGrow, false, "comment2 survey.autoGrowComment = false, #4");
assert.equal(comment3.renderedAutoGrow, false, "comment2 survey.autoGrowComment = false, #5");

survey.allowResizeComment = true;
survey.autoGrowComment = true;
assert.equal(comment1.renderedAllowResize, true, "comment1 survey.allowResizeComment = true");
assert.equal(comment1.autoGrow, true, "comment1 survey.autoGrowComment = true");
assert.equal(comment2.renderedAllowResize, true, "comment2 survey.allowResizeComment = true");
assert.equal(comment2.autoGrow, true, "comment2 survey.autoGrowComment = true");
assert.equal(comment1.renderedAllowResize, true, "comment1 survey.allowResizeComment = true, #6");
assert.equal(comment1.renderedAutoGrow, true, "comment1 survey.autoGrowComment = true, #7");
assert.equal(comment2.renderedAllowResize, true, "comment2 survey.allowResizeComment = true, #8");
assert.equal(comment2.renderedAutoGrow, true, "comment2 survey.autoGrowComment = true, #9");
assert.equal(comment3.renderedAutoGrow, false, "comment2 survey.autoGrowComment = true, #10");
});

QUnit.test("utils.increaseHeightByContent", assert => {
Expand Down

0 comments on commit ce5ff2d

Please sign in to comment.