impr(validation): don't debounce if delay is zero (@fehmer, @miodec) (#6878)

after #6866 set debounceDelay to 0 for email validation
This commit is contained in:
Christian Fehmer 2025-08-14 11:30:06 +02:00 committed by GitHub
parent 33e3acc70f
commit a3764460e4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 20 additions and 4 deletions

View file

@ -582,6 +582,9 @@ export const commandlineConfigMetadata: CommandlineConfigMetadataObject = {
fontSize: {
input: {
inputValueConvert: Number,
validation: {
isValid: async (number: number) => number < 100,
},
},
},
fontFamily: {

View file

@ -36,6 +36,18 @@ export type Validation<T> = {
/** Resets the value to the current config if empty */
resetIfEmpty?: false;
};
// oxlint-disable-next-line no-explicit-any
export function debounceIfNeeded<T extends (...args: any[]) => any>(
delay: number,
callback: T
): T | debounce<T> {
if (delay === undefined || delay <= 0) {
return callback;
}
return debounce(delay, callback);
}
/**
* Create input handler for validated input element.
* the `callback` is called for each validation state change, including "checking".
@ -51,7 +63,7 @@ export function createInputEventHandler<T>(
): (e: Event) => Promise<void> {
let callIsValid =
validation.isValid !== undefined
? debounce(
? debounceIfNeeded(
validation.debounceDelay ?? 100,
async (
originalInput: HTMLInputElement,
@ -115,7 +127,7 @@ export function createInputEventHandler<T>(
return;
}
callIsValid(originalInput, currentValue, checkValue as T);
await callIsValid(originalInput, currentValue, checkValue as T);
//call original handler if defined
originalInput.oninput?.(e);
};

View file

@ -21,7 +21,7 @@ const actionModals: Record<Action, SimpleModal> = {
{
placeholder: "tag name",
type: "text",
validation: { isValid: tagNameValidation },
validation: { isValid: tagNameValidation, debounceDelay: 0 },
},
],
onlineOnly: true,
@ -63,7 +63,7 @@ const actionModals: Record<Action, SimpleModal> = {
{
placeholder: "tag name",
type: "text",
validation: { isValid: tagNameValidation },
validation: { isValid: tagNameValidation, debounceDelay: 0 },
},
],
onlineOnly: true,

View file

@ -247,6 +247,7 @@ list.updateEmail = new SimpleModal({
isValid: async (currentValue, thisPopup) =>
currentValue === thisPopup.inputs?.[1]?.currentValue() ||
"Emails don't match",
debounceDelay: 0,
},
},
],