Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
FrameMuse committed Dec 20, 2022
1 parent 5dd505e commit 788b9df
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 25 deletions.
6 changes: 3 additions & 3 deletions src/ExampleForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ function GeneralInfoForm(props: GeneralInfoFormProps) {


const field = form.safeParseCurrentField(event)
if (field.success) {
console.log(field.data)
if (field.value.success) {
console.log(field.value.data)
} else {
console.log(field.error.formErrors.formErrors)
console.log(field.value.error.formErrors.formErrors)
}


Expand Down
8 changes: 5 additions & 3 deletions src/ZodForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import { FormEvent } from "react"
import { ZodFormOptions } from "./types"
import { z } from "zod"

class ZodForm<Output, Shape extends z.ZodRawShape = { [K in keyof Output]: z.ZodType<Output[K], z.ZodTypeDef, unknown> }> {
class ZodForm<Output, Shape extends z.ZodRawShape = {
[K in keyof Output]: z.ZodType<Output[K], z.ZodTypeDef, unknown>
}> {
public readonly object: z.ZodObject<Shape>
public readonly fields: Record<keyof Shape, string>
public readonly fieldNames: (keyof Shape)[]
Expand All @@ -36,13 +38,13 @@ class ZodForm<Output, Shape extends z.ZodRawShape = { [K in keyof Output]: z.Zod
public parseCurrentField(event: FormEvent<HTMLFormElement>) {
const { name, value } = FormTools.getCurrentValue(event, this.fieldNames, !this.options?.noTransform)

return this.object.shape[name].parse(value)
return { name, value: this.object.shape[name].parse(value) as Output[keyof Output] }
}

public safeParseCurrentField(event: FormEvent<HTMLFormElement>) {
const { name, value } = FormTools.getCurrentValue(event, this.fieldNames, !this.options?.noTransform)

return this.object.shape[name].safeParse(value)
return { name, value: this.object.shape[name].safeParse(value) }
}


Expand Down
19 changes: 0 additions & 19 deletions src/index.d.ts

This file was deleted.

0 comments on commit 788b9df

Please sign in to comment.