Skip to content

Commit 4348018

Browse files
MarchTokendaDmitrii Gerasimovandrewtelnov
authored
The Uncaught RangeError: Invalid time value exception occurs on an at… (#10668)
* The Uncaught RangeError: Invalid time value exception occurs on an attempt to load an invalid date to a specialized Month input element Bug#10663 * fix e2e test * Update expected survey result and input values CI browser behavior is different * Update text.spec.ts Remove e2e test. It is enough to have unit test. CI chrome create incorrect. --------- Co-authored-by: Dmitrii Gerasimov <[email protected]> Co-authored-by: Andrew <[email protected]>
1 parent e10ead1 commit 4348018

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

e2e/questions/text.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,4 +359,4 @@ frameworks.forEach((framework) => {
359359
expect(surveyResult.question3).toEqual(undefined);
360360
});
361361
});
362-
});
362+
});

packages/survey-core/src/question_text.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,10 @@ export class QuestionTextModel extends QuestionTextBase {
643643
const d = this.createDate(newValue);
644644
const isUtc = d.toISOString().indexOf(newValue) == 0 && newValue.indexOf("T") == -1;
645645
const month = isUtc ? d.getUTCMonth() : d.getMonth();
646-
const year = isUtc ? d.getUTCFullYear() : d.getFullYear();
646+
let year = (isUtc ? d.getUTCFullYear() : d.getFullYear()).toString();
647+
while(year.length < 4) {
648+
year = "0" + year;
649+
}
647650
const m = month + 1;
648651
return year + "-" + (m < 10 ? "0" : "") + m;
649652
}

packages/survey-core/tests/question_texttests.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,16 @@ QUnit.test("inputType='month' and today function, #8552", function(assert) {
479479
const etalon = new Date().getFullYear() + "-" + (m < 10 ? "0" : "") + m;
480480
assert.equal(q1.value, etalon, "today works correctly for month input");
481481
});
482+
QUnit.test("inputType='month' and when year is less than 1000 (4 digits) Bug#10663", function(assert) {
483+
const survey = new SurveyModel({
484+
"elements": [
485+
{ "type": "text", "name": "q1", "inputType": "month" },
486+
]
487+
});
488+
const q1 = <QuestionTextModel>survey.getQuestionByName("q1");
489+
q1.inputValue = "0133-5";
490+
assert.equal(q1.value, "0133-05", "the value is correct #3");
491+
});
482492
QUnit.test("inputType='date' invalid value, #8617", function(assert) {
483493
const survey = new SurveyModel({
484494
"elements": [

0 commit comments

Comments
 (0)