Skip to content

Commit

Permalink
Auto populate today's month fix #8552 (#8557)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov authored Jul 15, 2024
1 parent 159bf22 commit 1e05870
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/question_text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,9 +541,13 @@ export class QuestionTextModel extends QuestionTextBase {
}
protected correctValueType(newValue: any): any {
if (!newValue) return newValue;
if (this.inputType == "number" || this.inputType == "range") {
if (this.inputType === "number" || this.inputType === "range") {
return Helpers.isNumber(newValue) ? Helpers.getNumber(newValue) : "";
}
if(this.inputType === "month") {
const d = new Date(newValue);
return d.getFullYear() + "-" + (d.getMonth() + 1);
}
return newValue;
}
protected hasPlaceholder(): boolean {
Expand Down
10 changes: 10 additions & 0 deletions tests/question_texttests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,3 +458,13 @@ QUnit.test("settings.storeUtcDates = true, #8542", function(assert) {
assert.equal(q1.value.indexOf("Z"), -1, "Has no z symbol");
settings.storeUtcDates = false;
});
QUnit.test("inputType='month' and today function, #8552", function(assert) {
const survey = new SurveyModel({
"elements": [
{ "type": "text", "name": "q1", "defaultValueExpression": "today()", "inputType": "month" },
]
});
const q1 = <QuestionTextModel>survey.getQuestionByName("q1");
const etalon = new Date().getFullYear() + "-" + (new Date().getMonth() + 1);
assert.equal(q1.value, etalon, "today works correctly for month input");
});

0 comments on commit 1e05870

Please sign in to comment.