- Delete old Vite+Svelte frontend - Initialize new SvelteKit project with TypeScript - Configure Tailwind CSS v4 + DaisyUI - Implement JWT authentication with auto-refresh - Create login page with form validation (Zod) - Add protected route guards - Update Docker configuration for single-stage build - Add E2E tests with Playwright (6/11 passing) - Fix Svelte 5 reactivity with $state() runes Known issues: - 5 E2E tests failing (timing/async issues) - Token refresh implementation needs debugging - Validation error display timing
35 lines
1.3 KiB
JavaScript
35 lines
1.3 KiB
JavaScript
import { splitPath } from '../stringPath.js';
|
|
import { traversePath } from '../traversal.js';
|
|
const noCustomValidityDataAttribute = 'noCustomValidity';
|
|
export async function updateCustomValidity(validityEl, errors) {
|
|
// Always reset validity, in case it has been validated on the server.
|
|
if ('setCustomValidity' in validityEl) {
|
|
validityEl.setCustomValidity('');
|
|
}
|
|
if (noCustomValidityDataAttribute in validityEl.dataset)
|
|
return;
|
|
setCustomValidity(validityEl, errors);
|
|
}
|
|
export function setCustomValidityForm(formElement, errors) {
|
|
for (const el of formElement.querySelectorAll('input,select,textarea,button')) {
|
|
if (('dataset' in el && noCustomValidityDataAttribute in el.dataset) || !el.name) {
|
|
continue;
|
|
}
|
|
const path = traversePath(errors, splitPath(el.name));
|
|
const error = path && typeof path.value === 'object' && '_errors' in path.value
|
|
? path.value._errors
|
|
: path?.value;
|
|
setCustomValidity(el, error);
|
|
if (error)
|
|
return;
|
|
}
|
|
}
|
|
function setCustomValidity(el, errors) {
|
|
if (!('setCustomValidity' in el))
|
|
return;
|
|
const message = errors && errors.length ? errors.join('\n') : '';
|
|
el.setCustomValidity(message);
|
|
if (message)
|
|
el.reportValidity();
|
|
}
|