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)
- Putting dataType: 'json' to enable nested data in a enctype="multipart/form-data" always return value from input type="file" undefined HOT 2
- Conditional fields validation and default values HOT 2
- Unsupported valibot schema: file HOT 9
- How to construct a schema dynamically? HOT 1
- Not clear how to use with Svelte 5 props
- when using `zod-i18n-map`, field errors are `[undefined]` HOT 6
- Superforms with GridStack HOT 5
- Cannot access ZodValidation type HOT 1
- Not able to get refine to work with superValidate and zod adapter HOT 8
- File not available after validation in SPA mode HOT 1
- Parent loader is not invalidated HOT 1
- Docs for reset
- ArkType without default values HOT 13
- Type instantiation is excessively deep and possibly infinite with componentized fields HOT 3
- `FormPathArrays` always `never` HOT 1
- Deprecate events passed to enhance? HOT 6
- Superforms errors store not updated when navigating to same page via CSR HOT 2
- Is there a way to avoid using superValidate to create forms? HOT 2
- Better Punish Late, Reward Early validationMethod
- Updating a value twice hides change event HOT 1
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.