Skip to content

Commit

Permalink
Revert "FIO-8798: updated shape of the data of day component with hid…
Browse files Browse the repository at this point in the history
…den fields (#5760)"

This reverts commit e6711cb.
  • Loading branch information
lane-formio committed Sep 12, 2024
1 parent 7b7604b commit 5511439
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 58 deletions.
35 changes: 8 additions & 27 deletions src/components/day/Day.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ export default class DayComponent extends Field {
required: false
}
},
dayFirst: false,
defaultValue: ''
dayFirst: false
}, ...extend);
}

Expand Down Expand Up @@ -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('/');
}
Expand Down Expand Up @@ -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';
}
}
31 changes: 0 additions & 31 deletions src/components/day/Day.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit 5511439

Please sign in to comment.