feat(document): surface end-before-start inline on the date form (#678)
Add an endBeforeStart $derived to WhoWhenSection (lexicographic ISO compare, no Date object) that renders an inline error on the end-date field — border-red-400, aria-invalid, aria-describedby, and a #end-date-error <p> inside the existing aria-live region — with a ⚠ glyph so the cue is not colour-alone (WCAG 1.4.1). Save is not disabled; the server stays the gate. Wire ErrorCode INVALID_DATE_RANGE through errors.ts getErrorMessage and add the single key error_invalid_date_range to de/en/es, so the same translated string is used inline (client) and via getErrorMessage (server fallback). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -102,3 +102,49 @@ describe('WhoWhenSection — precision controls', () => {
|
||||
expect(raw?.querySelector('b')).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('WhoWhenSection — end-before-start inline validation (#678)', () => {
|
||||
it('shows an inline error on the end-date field when end is before start (AC1)', async () => {
|
||||
render(WhoWhenSection, {
|
||||
precision: 'RANGE',
|
||||
dateIso: '1917-01-11',
|
||||
endDateIso: '1917-01-10'
|
||||
});
|
||||
|
||||
const end = document.querySelector('input#metaDateEnd') as HTMLInputElement;
|
||||
await vi.waitFor(() => {
|
||||
expect(document.querySelector('#end-date-error')).not.toBeNull();
|
||||
expect(end.getAttribute('aria-invalid')).toBe('true');
|
||||
expect(end.className).toContain('border-red-400');
|
||||
});
|
||||
});
|
||||
|
||||
it('clears the inline error once the end date is corrected, without reload (AC5)', async () => {
|
||||
render(WhoWhenSection, {
|
||||
precision: 'RANGE',
|
||||
dateIso: '1917-01-11',
|
||||
endDateIso: '1917-01-10'
|
||||
});
|
||||
|
||||
await vi.waitFor(() => expect(document.querySelector('#end-date-error')).not.toBeNull());
|
||||
|
||||
const end = document.querySelector('input#metaDateEnd') as HTMLInputElement;
|
||||
end.value = '12.01.1917'; // now after the start
|
||||
end.dispatchEvent(new Event('input', { bubbles: true }));
|
||||
|
||||
await vi.waitFor(() => {
|
||||
expect(document.querySelector('#end-date-error')).toBeNull();
|
||||
expect(end.getAttribute('aria-invalid')).not.toBe('true');
|
||||
});
|
||||
});
|
||||
|
||||
it('does not show the inline error when precision is not RANGE', async () => {
|
||||
render(WhoWhenSection, {
|
||||
precision: 'DAY',
|
||||
dateIso: '1917-01-11',
|
||||
endDateIso: '1917-01-10'
|
||||
});
|
||||
|
||||
expect(document.querySelector('#end-date-error')).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user