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;
|
||||
initial: Partial<T>;
|
||||
onSubmit?: (v: T) => void;
|
||||
onSubmit?: (v: Partial<T>) => void;
|
||||
form: FlexibleForm<T>;
|
||||
onUpdate?: (d: Partial<T>) => void;
|
||||
}) {
|
||||
|
@ -58,8 +58,8 @@ export function FormProvider<T>({
|
||||
}: {
|
||||
initialValue?: Partial<T>;
|
||||
onUpdate?: (v: Partial<T>) => void;
|
||||
onSubmit?: (v: T) => void;
|
||||
computeFormState?: (v: T) => FormState<T>;
|
||||
onSubmit?: (v: Partial<T>, s: FormState<T> | undefined) => void;
|
||||
computeFormState?: (v: Partial<T>) => FormState<T>;
|
||||
children: ComponentChildren;
|
||||
}): VNode {
|
||||
// const value = useRef(initialValue ?? {});
|
||||
@ -85,7 +85,11 @@ export function FormProvider<T>({
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
//@ts-ignore
|
||||
if (onSubmit) onSubmit(value.current);
|
||||
if (onSubmit)
|
||||
onSubmit(
|
||||
value.current,
|
||||
!computeFormState ? undefined : computeFormState(value.current),
|
||||
);
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
|
@ -1,5 +1,8 @@
|
||||
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 { createNewForm } from "../handlers/forms.js";
|
||||
|
||||
@ -41,16 +44,26 @@ export function CreateAccount({
|
||||
: undefined,
|
||||
},
|
||||
repeat: {
|
||||
// error: !v.repeat
|
||||
// ? i18n.str`required`
|
||||
// // : v.repeat !== v.password
|
||||
// // ? i18n.str`doesn't match`
|
||||
// : undefined,
|
||||
error: !v.repeat
|
||||
? i18n.str`required`
|
||||
: v.repeat !== v.password
|
||||
? i18n.str`doesn't match`
|
||||
: undefined,
|
||||
},
|
||||
};
|
||||
}}
|
||||
onSubmit={async (v) => {
|
||||
onNewAccount(v.password);
|
||||
onSubmit={async (v, s) => {
|
||||
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">
|
||||
|
@ -32,7 +32,7 @@ export function UnlockAccount({
|
||||
<Form.Provider
|
||||
onSubmit={async (v) => {
|
||||
try {
|
||||
await onAccountUnlocked(v.password);
|
||||
await onAccountUnlocked(v.password!);
|
||||
|
||||
notifyInfo("Account unlocked" as TranslatedString);
|
||||
} catch (e) {
|
||||
|
Loading…
Reference in New Issue
Block a user