mirror of
https://github.com/bknd-io/bknd/
synced 2026-08-02 16:16:02 +00:00
added validator for rjsf, hook form via standard schema
This commit is contained in:
@@ -13,6 +13,7 @@ import {
|
||||
import { ModalBody, ModalFooter, type TCreateModalSchema, useStepContext } from "./CreateModal";
|
||||
import { useBkndData } from "ui/client/schema/data/use-bknd-data";
|
||||
import type { s } from "core/object/schema";
|
||||
import { standardSchemaResolver } from "@hookform/resolvers/standard-schema";
|
||||
|
||||
const schema = entitiesSchema;
|
||||
type Schema = s.Static<typeof schema>;
|
||||
@@ -41,8 +42,7 @@ export function StepEntityFields() {
|
||||
setValue,
|
||||
} = useForm({
|
||||
mode: "onTouched",
|
||||
// @todo: add resolver
|
||||
//resolver: typeboxResolver(schema),
|
||||
resolver: standardSchemaResolver(schema),
|
||||
defaultValues: initial as NonNullable<Schema>,
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
//import { typeboxResolver } from "@hookform/resolvers/typebox";
|
||||
|
||||
import { standardSchemaResolver } from "@hookform/resolvers/standard-schema";
|
||||
import { TextInput, Textarea } from "@mantine/core";
|
||||
import { useFocusTrap } from "@mantine/hooks";
|
||||
import { useForm } from "react-hook-form";
|
||||
@@ -17,8 +16,7 @@ export function StepEntity() {
|
||||
const { nextStep, stepBack, state, setState } = useStepContext<TCreateModalSchema>();
|
||||
const { register, handleSubmit, formState, watch, control } = useForm({
|
||||
mode: "onTouched",
|
||||
// @todo: add resolver
|
||||
//resolver: typeboxResolver(entitySchema),
|
||||
resolver: standardSchemaResolver(entitySchema),
|
||||
defaultValues: state.entities?.create?.[0] ?? {},
|
||||
});
|
||||
/*const data = watch();
|
||||
|
||||
@@ -12,6 +12,7 @@ import { useStepContext } from "ui/components/steps/Steps";
|
||||
import { useEvent } from "ui/hooks/use-event";
|
||||
import { ModalBody, ModalFooter, type TCreateModalSchema } from "./CreateModal";
|
||||
import { s, stringIdentifier } from "core/object/schema";
|
||||
import { standardSchemaResolver } from "@hookform/resolvers/standard-schema";
|
||||
|
||||
const Relations: {
|
||||
type: RelationType;
|
||||
@@ -66,8 +67,7 @@ export function StepRelation() {
|
||||
watch,
|
||||
control,
|
||||
} = useForm({
|
||||
// @todo: implement resolver
|
||||
//resolver: typeboxResolver(schema),
|
||||
resolver: standardSchemaResolver(schema),
|
||||
defaultValues: (state.relations?.create?.[0] ?? {}) as s.Static<typeof schema>,
|
||||
});
|
||||
const data = watch();
|
||||
|
||||
+2
-2
@@ -15,6 +15,7 @@ import {
|
||||
useStepContext,
|
||||
} from "../../CreateModal";
|
||||
import { s, stringIdentifier } from "core/object/schema";
|
||||
import { standardSchemaResolver } from "@hookform/resolvers/standard-schema";
|
||||
|
||||
const schema = s.object({
|
||||
entity: stringIdentifier,
|
||||
@@ -34,8 +35,7 @@ export function TemplateMediaComponent() {
|
||||
control,
|
||||
} = useForm({
|
||||
mode: "onChange",
|
||||
// @todo: add resolver
|
||||
//resolver: typeboxResolver(schema),
|
||||
resolver: standardSchemaResolver(schema),
|
||||
defaultValues: schema.template(state.initial ?? {}) as TCreateModalMediaSchema,
|
||||
//defaultValues: Default(schema, state.initial ?? {}) as TCreateModalMediaSchema,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user