Skip to content

Commit

Permalink
Add minValueExpression/maxValueExpression properties into multiple te…
Browse files Browse the repository at this point in the history
…xt item fix #7146 (#7147)
  • Loading branch information
andrewtelnov committed Oct 14, 2023
1 parent f3e6578 commit 7732288
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
36 changes: 35 additions & 1 deletion src/question_multipletext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { SurveyElement } from "./survey-element";
import { SurveyValidator, IValidatorOwner } from "./validator";
import { Question, IConditionObject } from "./question";
import { QuestionTextModel } from "./question_text";
import { QuestionTextModel, isMinMaxType } from "./question_text";
import { JsonObject, Serializer, property, propertyArray } from "./jsonobject";
import { QuestionFactory } from "./questionfactory";
import { SurveyError } from "./survey-error";
Expand Down Expand Up @@ -208,6 +208,24 @@ export class MultipleTextItemModel extends Base
public set size(val: number) {
this.editor.size = val;
}
/**
* The minimum value specified as an expression. For example, `"minValueExpression": "today(-1)"` sets the minimum value to yesterday.
*/
public get minValueExpression(): string {
return this.editor.minValueExpression;
}
public set minValueExpression(val: string) {
this.editor.minValueExpression = val;
}
/**
* The maximum value specified as an expression. For example, `"maxValueExpression": "today(1)"` sets the maximum value to tomorrow.
*/
public get maxValueExpression(): string {
return this.editor.maxValueExpression;
}
public set maxValueExpression(val: string) {
this.editor.maxValueExpression = val;
}
/**
* The list of question validators.
*/
Expand Down Expand Up @@ -782,6 +800,22 @@ Serializer.addClass(
name: "requiredErrorText:text",
serializationProperty: "locRequiredErrorText",
},
{
name: "minValueExpression:expression",
category: "logic",
dependsOn: "inputType",
visibleIf: function(obj: any) {
return isMinMaxType(obj);
},
},
{
name: "maxValueExpression:expression",
category: "logic",
dependsOn: "inputType",
visibleIf: function(obj: any) {
return isMinMaxType(obj);
},
},
{
name: "validators:validators",
baseClassName: "surveyvalidator",
Expand Down
2 changes: 1 addition & 1 deletion src/question_text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ const minMaxTypes = [
"week",
];

function isMinMaxType(obj: any): boolean {
export function isMinMaxType(obj: any): boolean {
const t = !!obj ? obj.inputType : "";
if(!t) return false;
return minMaxTypes.indexOf(t) > -1;
Expand Down
20 changes: 20 additions & 0 deletions tests/question_multipletexttests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,23 @@ QUnit.test("Check error row visibility", (assert) => {
question.items[1].editor.value = "test";
assert.notOk(question.getRows()[0].isVisible);
});
QUnit.test("Load min/maxValueExpression from JSON", (assert) => {
const survey = new SurveyModel({
questions: [
{
type: "multipletext",
name: "q1",
items: [
{
name: "item1",
minValueExpression: 1,
maxValueExpression: 10,
}
]
}
]
});
const question = <QuestionMultipleTextModel>survey.getQuestionByName("q1");
assert.equal(question.items[0].minValueExpression, 1);
assert.equal(question.items[0].maxValueExpression, 10);
});

0 comments on commit 7732288

Please sign in to comment.