Skip to content

Commit

Permalink
resolve #8059 - Dynamic Matrix - The Date Input Mask resets the enter…
Browse files Browse the repository at this point in the history
…ed value
  • Loading branch information
OlgaLarina committed Apr 5, 2024
1 parent 5b9afa0 commit b9a1703
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/mask/mask_datetime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,22 @@ export class InputMaskDateTime extends InputMaskPattern {
});
}

private getISO_8601Format(dateTime: IDateTimeComposition): string {
if(dateTime.year === undefined || dateTime.month === undefined || dateTime.day === undefined) return "";
public getISO_8601Format(dateTime: IDateTimeComposition): string {
const date: Array<string> = [];

const year = this.getPlaceholder(4, dateTime.year.toString(), "0") + dateTime.year;
const month = this.getPlaceholder(2, dateTime.month.toString(), "0") + dateTime.month;
const day = this.getPlaceholder(2, dateTime.day.toString(), "0") + dateTime.day;
return [year, month, day].join("-");
if(dateTime.year !== undefined) {
const year = this.getPlaceholder(4, dateTime.year.toString(), "0") + dateTime.year;
date.push(year);
}
if(dateTime.month !== undefined && dateTime.year !== undefined) {
const month = this.getPlaceholder(2, dateTime.month.toString(), "0") + dateTime.month;
date.push(month);
}
if(dateTime.day !== undefined && dateTime.month !== undefined && dateTime.year !== undefined) {
const day = this.getPlaceholder(2, dateTime.day.toString(), "0") + dateTime.day;
date.push(day);
}
return date.join("-");
}

private isYearValid(dateTime: IDateTimeComposition): boolean {
Expand Down
16 changes: 16 additions & 0 deletions tests/mask/mask_datetime_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,22 @@ QUnit.test("get getMaskedValue value from ISO m/d/yy", function(assert) {
assert.equal(maskInstance.getMaskedValue("2024-13-05"), "m/d/yy");
});

QUnit.test("getISO_8601Format", function(assert) {
const maskInstance = new InputMaskDateTime();

maskInstance.pattern = "yyyy";
assert.equal(maskInstance.getUnmaskedValue("2024"), "2024");

maskInstance.pattern = "mm/yyyy";
assert.equal(maskInstance.getUnmaskedValue("09/2024"), "2024-09");

maskInstance.pattern = "m/yyyy";
assert.equal(maskInstance.getUnmaskedValue("9/2024"), "2024-09");

maskInstance.pattern = "m/yy";
assert.equal(maskInstance.getUnmaskedValue("9/24"), "2024-09");
});

QUnit.test("get masked date if text with dots mm/dd/yyyy", function(assert) {
const maskInstance = new InputMaskDateTime();
maskInstance.pattern = "mm/dd/yyyy";
Expand Down

0 comments on commit b9a1703

Please sign in to comment.