fix(login): use onChange instead of onBlur with react-hook-form (#11354)

# Which Problems Are Solved

Fixes a problem where submit buttons where not correctly enabled onBlur
event

# How the Problems Are Solved

By changing the react-hook-form mode property to onChange, buttons are
enabled as intended
This commit is contained in:
Max Peintner
2026-01-14 08:07:04 +00:00
committed by GitHub
parent 86fd769439
commit cd36abd725
13 changed files with 38 additions and 131 deletions
@@ -1,16 +1,7 @@
"use client";
import {
lowerCaseValidator,
numberValidator,
symbolValidator,
upperCaseValidator,
} from "@/helpers/validators";
import {
changePassword,
resetPassword,
sendPassword,
} from "@/lib/server/password";
import { lowerCaseValidator, numberValidator, symbolValidator, upperCaseValidator } from "@/helpers/validators";
import { changePassword, resetPassword, sendPassword } from "@/lib/server/password";
import { create } from "@zitadel/client";
import { ChecksSchema } from "@zitadel/proto/zitadel/session/v2/session_service_pb";
import { PasswordComplexitySettings } from "@zitadel/proto/zitadel/settings/v2/password_settings_pb";
@@ -54,7 +45,7 @@ export function SetPasswordForm({
codeRequired,
}: Props) {
const { register, handleSubmit, watch, formState } = useForm<Inputs>({
mode: "onBlur",
mode: "onChange",
defaultValues: {
code: code ?? "",
},
@@ -148,20 +139,12 @@ export function SetPasswordForm({
setLoading(false);
});
if (
passwordResponse &&
"error" in passwordResponse &&
passwordResponse.error
) {
if (passwordResponse && "error" in passwordResponse && passwordResponse.error) {
setError(passwordResponse.error);
return;
}
if (
passwordResponse &&
"redirect" in passwordResponse &&
passwordResponse.redirect
) {
if (passwordResponse && "redirect" in passwordResponse && passwordResponse.redirect) {
return router.push(passwordResponse.redirect);
}
@@ -173,9 +156,7 @@ export function SetPasswordForm({
const watchPassword = watch("password", "");
const watchConfirmPassword = watch("confirmPassword", "");
const hasMinLength =
passwordComplexitySettings &&
watchPassword?.length >= passwordComplexitySettings.minLength;
const hasMinLength = passwordComplexitySettings && watchPassword?.length >= passwordComplexitySettings.minLength;
const hasSymbol = symbolValidator(watchPassword);
const hasNumber = numberValidator(watchPassword);
const hasUppercase = upperCaseValidator(watchPassword);
@@ -271,17 +252,11 @@ export function SetPasswordForm({
<Button
type="submit"
variant={ButtonVariants.Primary}
disabled={
loading ||
!policyIsValid ||
!formState.isValid ||
watchPassword !== watchConfirmPassword
}
disabled={loading || !policyIsValid || !formState.isValid || watchPassword !== watchConfirmPassword}
onClick={handleSubmit(submitPassword)}
data-testid="submit-button"
>
{loading && <Spinner className="mr-2 h-5 w-5" />}{" "}
<Translated i18nKey="set.submit" namespace="password" />
{loading && <Spinner className="mr-2 h-5 w-5" />} <Translated i18nKey="set.submit" namespace="password" />
</Button>
</div>
</form>