Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add json example #686

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

lifeiscontent
Copy link
Contributor

@edmundhung can you explain to me how I might be able to get a JSON field working with conform? I've setup this example, but the .defaultValue of the input renders as a blank input value

Copy link

changeset-bot bot commented Jun 18, 2024

⚠️ No Changeset found

Latest commit: 3c043ee

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@edmundhung
Copy link
Owner

edmundhung commented Jun 20, 2024

Just pushed a commit to your PR.

There is no JSON field in Conform. Conform only understand string or File in an input. You will need to serialize it manually and make sure it to be serialized again when you access and update the field value (e.g. control.change(JSON.serialize(value)) or JSON.parse(control.value))

It might be worth adding an option to the useControl hook to handle the serialziation for you 🤔

@lifeiscontent
Copy link
Contributor Author

@edmundhung is there anyway to use the jsonSchema type I had? for my use case I want to allow someone to add any JSON data because we're mapping it back to a users DB so we don't know the shape of the data.

@edmundhung
Copy link
Owner

I have tested it once with your original type and it seems to recursively looping over and over again and crash. I am not sure why. It might be either a bug on the enableTypeCoercion helper in the conform zod package or something wrong with zod itself? Can you verify if the JSON schema works without passing to Conform?

@lifeiscontent
Copy link
Contributor Author

lifeiscontent commented Jun 20, 2024

@edmundhung yep the jsonSchema type is in the GitHub docs of zod and works as expected https://github.com/colinhacks/zod?tab=readme-ov-file#json-type

@edmundhung
Copy link
Owner

@lifeiscontent I have pushed up a fix to your branch. Let me know if this is what you were looking for.

@lifeiscontent
Copy link
Contributor Author

@edmundhung is there a way I can try a prerelease version of this quickly? I can try it in the project I'm working in and get back to you.

Copy link

pkg-pr-new bot commented Aug 17, 2024

commit: 3c043ee

@conform-to/dom

pnpm add https://pkg.pr.new/@conform-to/dom@686

@conform-to/react

pnpm add https://pkg.pr.new/@conform-to/react@686

@conform-to/validitystate

pnpm add https://pkg.pr.new/@conform-to/validitystate@686

@conform-to/yup

pnpm add https://pkg.pr.new/@conform-to/yup@686

@conform-to/zod

pnpm add https://pkg.pr.new/@conform-to/zod@686

Open in Stackblitz

More templates

@edmundhung
Copy link
Owner

edmundhung commented Aug 17, 2024

@edmundhung is there a way I can try a prerelease version of this quickly? I can try it in the project I'm working in and get back to you.

Here you go ☝🏼

@lifeiscontent
Copy link
Contributor Author

@edmundhung it works perfectly! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants