diff --git a/src/components/day/Day.js b/src/components/day/Day.js index 2cad5215ed..4f51b6b2eb 100644 --- a/src/components/day/Day.js +++ b/src/components/day/Day.js @@ -26,8 +26,7 @@ export default class DayComponent extends Field { required: false } }, - dayFirst: false, - defaultValue: '' + dayFirst: false }, ...extend); } @@ -388,25 +387,20 @@ export default class DayComponent extends Field { const [DAY, MONTH, YEAR] = this.component.dayFirst ? [0, 1, 2] : [1, 0, 2]; const defaultValue = this.component.defaultValue ? this.component.defaultValue.split('/') : ''; - const getNextPart = (shouldTake, defaultValue) => { - // Only push the part if it's not an empty string - const part = shouldTake ? valueParts.shift() : defaultValue; - if (part !== '') { - dateParts.push(part); - } - }; + const getNextPart = (shouldTake, defaultValue) => + dateParts.push(shouldTake ? valueParts.shift() : defaultValue); if (this.dayFirst) { - getNextPart(this.showDay, defaultValue ? defaultValue[DAY] : ''); + getNextPart(this.showDay, defaultValue ? defaultValue[DAY] : '00'); } - getNextPart(this.showMonth, defaultValue ? defaultValue[MONTH] : ''); + getNextPart(this.showMonth, defaultValue ? defaultValue[MONTH] : '00'); if (!this.dayFirst) { - getNextPart(this.showDay, defaultValue ? defaultValue[DAY] : ''); + getNextPart(this.showDay, defaultValue ? defaultValue[DAY] : '00'); } - getNextPart(this.showYear, defaultValue ? defaultValue[YEAR] : ''); + getNextPart(this.showYear, defaultValue ? defaultValue[YEAR] : '0000'); return dateParts.join('/'); } @@ -639,23 +633,10 @@ export default class DayComponent extends Field { } const [DAY, MONTH, YEAR] = this.component.dayFirst ? [0, 1, 2] : [1, 0, 2]; const values = value.split('/'); - if (values.length < 3) { - return true; - } return (values[DAY] === '00' || values[MONTH] === '00' || values[YEAR] === '0000'); } getValidationFormat() { - let validationFormat = this.dayFirst ? 'DD-MM-YYYY' : 'MM-DD-YYYY'; - if (this.fields?.day?.hide) { - validationFormat = validationFormat.replace('DD-', ''); - } - if (this.fields?.month?.hide) { - validationFormat = validationFormat.replace('MM-', ''); - } - if ( this.fields?.year?.hide ) { - validationFormat = validationFormat.replace('-YYYY', ''); - } - return validationFormat; + return this.dayFirst ? 'DD-MM-YYYY' : 'MM-DD-YYYY'; } } diff --git a/src/components/day/Day.unit.js b/src/components/day/Day.unit.js index dbf4c136ad..fb65885e93 100644 --- a/src/components/day/Day.unit.js +++ b/src/components/day/Day.unit.js @@ -200,37 +200,6 @@ describe('Day Component', () => { }); }); - it('Should set value if the day field is hidden', (done) => { - comp1.dayFirst = false; - comp1.fields.day.hide = true; - Harness.testCreate(DayComponent, comp1).then((component) => { - component.setValue('12/2023'); - assert.equal(component.data.date, '12/2023'); - done(); - }); - comp1.fields.day.hide = false; - }); - - it('Should set value if the month field is hidden', (done) => { - comp1.fields.month.hide = true; - Harness.testCreate(DayComponent, comp1).then((component) => { - component.setValue('12/2023'); - assert.equal(component.data.date, '12/2023'); - done(); - }); - comp1.fields.month.hide = false; - }); - - it('Should set value if the year field is hidden', (done) => { - comp1.fields.year.hide = true; - Harness.testCreate(DayComponent, comp1).then((component) => { - component.setValue('12/21'); - assert.equal(component.data.date, '12/21'); - done(); - }); - comp1.fields.year.hide = false; - }); - it('Should use the default day value if the day field is hidden', (done) => { comp1.dayFirst = false; comp1.defaultValue = '00/01/0000';