Comments (14)
- Use a very minimal, basic, generic schema to satisfy SuperForms.
- Get any errors from
const validate = ajv.compile(schema); validate(data)
- Format and feed these errors to SuperForms
setError()
Note I got this to work with SuperForms SPA mode after submitting the form (in one of the events).
- I couldn't get real-time validation to work. I couldn't see any "hooks" I could use where
setError
was available. - The
$errors
store is writeable, but updating it didn't seem to work well (my updates were either overwritten or ignored). - I did not try with form actions.
My feature that required ajv + dynamic json-schema ended up being dropped. Otherwise I would have probably just rendered the validation errors from ajv manually myself and not used SuperForms for validation.
from sveltekit-superforms.
As this is very complicated, making ajv work with ESM and moduleResolution is the best bet. Could need some help with that.
from sveltekit-superforms.
Ah, since SuperForms uses JSON schema internally, I thought a jsonschema
adapter wouldn't be difficult to add... (I looked at the SuperForms code myself, but wasn't sure how to do it.)
making ajv work with ESM and moduleResolution is the best bet. Could need some help with that.
I'd like to help, but I'm not sure what the problem is:
- Does SuperForms fail to compile if ajv is included?
- I'm using ajv in my SvelteKit project without issue
- Is it just the bundle size because code-shaking is not possible?
- If it's just the bundle size, is it possible to split the ajv adapter from the rest of the package so the bundle size only affects ajv users? I think ajv support with a larger bundle size would be preferrable to no support at all.
Also there seem to be several other JSON schema libraries listed since I last investigated. Could adapters be added for any of those? Like Hyperjump JSV or djv?
Also, I did get formdata validation with ajv working outside of SuperForms (in real-time onchange events on the client). I'm just having trouble updating SuperForms $errors
with the validation errors on the client side. I've only managed to get it to work inside the onUpdate()
event (in SPA mode).
from sveltekit-superforms.
Since it's not tree-shakable (by not being ESM-compatible), it's basically included as long as it exists in the project as a dependency, no matter what library you're using. So I can't really add it until it's thoroughly fixed in the library itself.
Hyperjump looks nice, and seems modern, so it looks like a candidate. Basically any adapter can be used as a base, but typebox could be suitable. Type inference is probably not available in Hyperjump, but you could use json-schema-to-ts for that, if it's tree-shakable. X) It can be a bit slow though, in my tests.
from sveltekit-superforms.
I am currently trying to implement something similar @Leftium. Basically, I building support for a form builder that defines its fields using json-schema directly. Having the option to directly pass "raw" JSON schema to superforms (or first class support a validation library that supports it) would be amazing! (Just wanted to add my +1 to this)
@Leftium would it be possible to share the workaround using ajv manually? Thanks in advance!
from sveltekit-superforms.
@ciscoheat As mentioned on discord, I might look into implementing a new adapter that could support raw json-schema (not sure how easy type inference is going to be, but let's see).
It seems like you have implemented code for ajv at some point, but removed it from the repo. Is that still around? might be a good starting point.
from sveltekit-superforms.
Yes, here's the version before it was removed: https://github.com/ciscoheat/sveltekit-superforms/blob/bd221dd44fa41dadd30965d050975eee067191df/src/lib/adapters/ajv.ts
from sveltekit-superforms.
The Typebox adapter (latest version) should be useful for making it use the latest interface and helpers: https://github.com/ciscoheat/sveltekit-superforms/blob/main/src/lib/adapters/typebox.ts
from sveltekit-superforms.
so, which adapter can we use for json schema validation?
from sveltekit-superforms.
Just found https://github.com/sagold/json-schema-library which looks promising, but I don't know about any details.
from sveltekit-superforms.
Hi, am facing a roadblock on this issue as well. Any help needed to implement this?
from sveltekit-superforms.
It's ready to merge, just need to find the time.
from sveltekit-superforms.
Here is the validator being used, btw; https://github.com/ExodusMovement/schemasafe
from sveltekit-superforms.
Added now with 2.13.0: https://superforms.rocks/get-started/json-schema
from sveltekit-superforms.
Related Issues (20)
- Error when using `.optional()` with `.refine()` with Zod HOT 3
- Posted store is set to true even when data is invalid HOT 6
- Refine with Path creates nested error object. HOT 2
- Returning files from load function does not work HOT 2
- how to set additional header data when we submit the form ? HOT 1
- Array Errors Structure HOT 2
- Snapshots with componentized form HOT 2
- Vine & other deps getting unnecessarily installed HOT 1
- Validation doesn't work with different pages HOT 1
- New Adapter: @effect/schema HOT 3
- OpenAPI/Pydantic Validation Support HOT 3
- How to set an error during onSubmit() HOT 1
- Clearing previously stored errors on client HOT 8
- Two forms in same page. When a submit the form 2, data returned in form 1 is cleared. HOT 1
- [Question]What is the good practice of returning `fail` caused by things other than form validation errors? HOT 2
- Provide reducers/reviviers for devalue in superForm/superValidate functions HOT 1
- After submit the validation data is empty HOT 5
- Proxy object in nested array HOT 6
- Superforms is not compatible with Svelte 5 (preview) in rune mode HOT 2
- Error with use:enhance when using on Safari IOS 13.6 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sveltekit-superforms.