fix(ux): locale reload feedback, submit validation, dedup blur logic
- Locale-Picker: disable select + fade before location.reload() (system mode) gives visual feedback before the page jumps - Extract _validateField() helper from wireBlurValidation to avoid duplication - Add validateAll(formContainer): validates all required fields on demand, marks inline errors, focuses first invalid field - tasks.js: call validateAll() at submit to catch untouched required fields
This commit is contained in:
@@ -484,21 +484,45 @@ export function confirmModal(message, { confirmLabel, danger = false } = {}) {
|
||||
// Inline Blur-Validierung
|
||||
// --------------------------------------------------------
|
||||
|
||||
function _validateField(input) {
|
||||
const group = input.closest('.form-field') ?? input.parentElement;
|
||||
const hasValue = input.value.trim().length > 0;
|
||||
group?.classList.toggle('form-field--error', !hasValue);
|
||||
group?.classList.toggle('form-field--valid', hasValue);
|
||||
return hasValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Aktiviert Blur-Validierung für alle required-Inputs in einem Container.
|
||||
* @param {HTMLElement} formContainer
|
||||
*/
|
||||
export function wireBlurValidation(formContainer) {
|
||||
formContainer.querySelectorAll('input[required], select[required], textarea[required]').forEach((input) => {
|
||||
input.addEventListener('blur', () => {
|
||||
const group = input.closest('.form-field') ?? input.parentElement;
|
||||
const hasValue = input.value.trim().length > 0;
|
||||
group?.classList.toggle('form-field--error', !hasValue);
|
||||
group?.classList.toggle('form-field--valid', hasValue);
|
||||
});
|
||||
input.addEventListener('blur', () => _validateField(input));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Validiert alle required-Inputs sofort (z.B. beim Submit ohne vorangehendes Blur).
|
||||
* Markiert Fehler inline und fokussiert das erste ungültige Feld.
|
||||
*
|
||||
* @param {HTMLElement} formContainer
|
||||
* @returns {boolean} true wenn alle Felder valide sind
|
||||
*/
|
||||
export function validateAll(formContainer) {
|
||||
let firstInvalid = null;
|
||||
let allValid = true;
|
||||
|
||||
formContainer.querySelectorAll('input[required], select[required], textarea[required]').forEach((input) => {
|
||||
const valid = _validateField(input);
|
||||
if (!valid && !firstInvalid) firstInvalid = input;
|
||||
if (!valid) allValid = false;
|
||||
});
|
||||
|
||||
if (firstInvalid) firstInvalid.focus();
|
||||
return allValid;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------
|
||||
// Submit-Feedback (Checkmark + Shake)
|
||||
// --------------------------------------------------------
|
||||
|
||||
@@ -55,8 +55,11 @@ class OikosLocalePicker extends HTMLElement {
|
||||
|
||||
select.addEventListener('change', () => {
|
||||
if (select.value === 'system') {
|
||||
select.disabled = true;
|
||||
select.style.opacity = '0.5';
|
||||
localStorage.removeItem('oikos-locale');
|
||||
location.reload();
|
||||
// Kurze Verzögerung damit der Browser den disabled-Zustand rendert
|
||||
setTimeout(() => location.reload(), 60);
|
||||
} else {
|
||||
setLocale(select.value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user