compute some error on submit
This commit is contained in:
parent
8d85426f0e
commit
f5f3d3e23c
@ -13,7 +13,7 @@ export function NiceForm<T extends object>({
|
|||||||
}: {
|
}: {
|
||||||
children?: ComponentChildren;
|
children?: ComponentChildren;
|
||||||
initial: Partial<T>;
|
initial: Partial<T>;
|
||||||
onSubmit?: (v: T) => void;
|
onSubmit?: (v: Partial<T>) => void;
|
||||||
form: FlexibleForm<T>;
|
form: FlexibleForm<T>;
|
||||||
onUpdate?: (d: Partial<T>) => void;
|
onUpdate?: (d: Partial<T>) => void;
|
||||||
}) {
|
}) {
|
||||||
|
@ -58,8 +58,8 @@ export function FormProvider<T>({
|
|||||||
}: {
|
}: {
|
||||||
initialValue?: Partial<T>;
|
initialValue?: Partial<T>;
|
||||||
onUpdate?: (v: Partial<T>) => void;
|
onUpdate?: (v: Partial<T>) => void;
|
||||||
onSubmit?: (v: T) => void;
|
onSubmit?: (v: Partial<T>, s: FormState<T> | undefined) => void;
|
||||||
computeFormState?: (v: T) => FormState<T>;
|
computeFormState?: (v: Partial<T>) => FormState<T>;
|
||||||
children: ComponentChildren;
|
children: ComponentChildren;
|
||||||
}): VNode {
|
}): VNode {
|
||||||
// const value = useRef(initialValue ?? {});
|
// const value = useRef(initialValue ?? {});
|
||||||
@ -85,7 +85,11 @@ export function FormProvider<T>({
|
|||||||
onSubmit={(e) => {
|
onSubmit={(e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
if (onSubmit) onSubmit(value.current);
|
if (onSubmit)
|
||||||
|
onSubmit(
|
||||||
|
value.current,
|
||||||
|
!computeFormState ? undefined : computeFormState(value.current),
|
||||||
|
);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
import { TranslatedString } from "@gnu-taler/taler-util";
|
import { TranslatedString } from "@gnu-taler/taler-util";
|
||||||
import { useTranslationContext } from "@gnu-taler/web-util/browser";
|
import {
|
||||||
|
notifyError,
|
||||||
|
useTranslationContext,
|
||||||
|
} from "@gnu-taler/web-util/browser";
|
||||||
import { VNode, h } from "preact";
|
import { VNode, h } from "preact";
|
||||||
import { createNewForm } from "../handlers/forms.js";
|
import { createNewForm } from "../handlers/forms.js";
|
||||||
|
|
||||||
@ -41,16 +44,26 @@ export function CreateAccount({
|
|||||||
: undefined,
|
: undefined,
|
||||||
},
|
},
|
||||||
repeat: {
|
repeat: {
|
||||||
// error: !v.repeat
|
error: !v.repeat
|
||||||
// ? i18n.str`required`
|
? i18n.str`required`
|
||||||
// // : v.repeat !== v.password
|
: v.repeat !== v.password
|
||||||
// // ? i18n.str`doesn't match`
|
? i18n.str`doesn't match`
|
||||||
// : undefined,
|
: undefined,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}}
|
}}
|
||||||
onSubmit={async (v) => {
|
onSubmit={async (v, s) => {
|
||||||
onNewAccount(v.password);
|
console.log(v, s);
|
||||||
|
const error = s?.password?.error ?? s?.repeat?.error;
|
||||||
|
console.log(error);
|
||||||
|
if (error) {
|
||||||
|
notifyError(
|
||||||
|
"Can't create account" as TranslatedString,
|
||||||
|
error as TranslatedString,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
onNewAccount(v.password!);
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div class="mb-4">
|
<div class="mb-4">
|
||||||
|
@ -32,7 +32,7 @@ export function UnlockAccount({
|
|||||||
<Form.Provider
|
<Form.Provider
|
||||||
onSubmit={async (v) => {
|
onSubmit={async (v) => {
|
||||||
try {
|
try {
|
||||||
await onAccountUnlocked(v.password);
|
await onAccountUnlocked(v.password!);
|
||||||
|
|
||||||
notifyInfo("Account unlocked" as TranslatedString);
|
notifyInfo("Account unlocked" as TranslatedString);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user