Enable the errors to be displayed immediately and not after focus is lost
This commit is contained in:
@ -59,6 +59,8 @@ export type FormAction =
|
|||||||
action: "update";
|
action: "update";
|
||||||
name: string;
|
name: string;
|
||||||
valueOrValues: string | string[];
|
valueOrValues: string | string[];
|
||||||
|
/** Default false */
|
||||||
|
displayErrorsImmediately?: boolean;
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
action: "focus lost";
|
action: "focus lost";
|
||||||
@ -413,6 +415,24 @@ export function useUserProfileForm(params: UseUserProfileFormParams): ReturnType
|
|||||||
formFieldStates: state.formFieldStates
|
formFieldStates: state.formFieldStates
|
||||||
});
|
});
|
||||||
|
|
||||||
|
simulate_focus_lost: {
|
||||||
|
const { displayErrorsImmediately = false } = formAction;
|
||||||
|
|
||||||
|
if (!displayErrorsImmediately) {
|
||||||
|
break simulate_focus_lost;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const fieldIndex of formAction.valueOrValues instanceof Array
|
||||||
|
? formAction.valueOrValues.map((...[, index]) => index)
|
||||||
|
: [undefined]) {
|
||||||
|
state = reducer(state, {
|
||||||
|
action: "focus lost",
|
||||||
|
name: formAction.name,
|
||||||
|
fieldIndex
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
update_password_confirm: {
|
update_password_confirm: {
|
||||||
if (doMakeUserConfirmPassword) {
|
if (doMakeUserConfirmPassword) {
|
||||||
break update_password_confirm;
|
break update_password_confirm;
|
||||||
@ -425,7 +445,8 @@ export function useUserProfileForm(params: UseUserProfileFormParams): ReturnType
|
|||||||
state = reducer(state, {
|
state = reducer(state, {
|
||||||
action: "update",
|
action: "update",
|
||||||
name: "password-confirm",
|
name: "password-confirm",
|
||||||
valueOrValues: formAction.valueOrValues
|
valueOrValues: formAction.valueOrValues,
|
||||||
|
displayErrorsImmediately: formAction.displayErrorsImmediately
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -447,7 +468,8 @@ export function useUserProfileForm(params: UseUserProfileFormParams): ReturnType
|
|||||||
assert(formFieldState !== undefined);
|
assert(formFieldState !== undefined);
|
||||||
|
|
||||||
return formFieldState.valueOrValues;
|
return formFieldState.valueOrValues;
|
||||||
})()
|
})(),
|
||||||
|
displayErrorsImmediately: formAction.displayErrorsImmediately
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user