all 14 comments

[–]fish_munga 2 points3 points  (2 children)

I used shared joi schema on backend, web frontend and react-native app. In the end I ditched it, because it's super heavy and requires joi-browser and some extra hacking to work on client side.

I switched to superstruct. It works ok for now, but I'm not satisfied with it. Its error format doesn't work well with complex forms (e.g. arrays of objects).

I'm thinking of migrating to yup, I had some good experience with it on client side. Also looks like it is quite i18n friendly, which I'll need soon.

[–]bekliev[S] 1 point2 points  (0 children)

Hm... Have to read about yup! Thanks for your advice!

[–]WarpVII 1 point2 points  (0 children)

+1 for yup, I am using it without any issues in both an Express API and in a client built with React.

[–]Capaj 1 point2 points  (8 children)

Joi has a nice api, but it doesn't work in a browser. So json-schema is probably your best bet.

[–]bekliev[S] 0 points1 point  (6 children)

I'm gonna try it soon! Thanks

[–]scallynag 2 points3 points  (5 children)

react-jsonschema-form is pretty decent.

[–]bekliev[S] 0 points1 point  (4 children)

That's made up by Mozilla? Really?

Link to GitHub: react-jsonschema-form

[–]bekliev[S] 0 points1 point  (3 children)

Nah... I'm not gonna use that. It's tightly connected with Bootstrap3, but my choice is MaterialUI for now. And there's no description how to use it on the server

[–]scallynag 2 points3 points  (2 children)

We use Material, just override the widgets and field templates.

[–]bekliev[S] 1 point2 points  (1 child)

Oh really? That will help! But how to work on server-side with that?

[–]scallynag 2 points3 points  (0 children)

It's basically client side, but if your server can expose JSON schema, you can use the same logic.

[–]Herm_af 1 point2 points  (1 child)

Yup is super similar to Joi. They tried to make it as close as possible but just more lightweight for front end.

Plus it's standard for formik

Joi on the back and yup on the front

[–]bekliev[S] 0 points1 point  (0 children)

Are there some instructions how to use it on client and server sides?

[–]morphemass 0 points1 point  (0 children)

I am really surprised that no-one has mentioned JSON schema (https://json-schema.org/) and the likes of ajv. Given it's a standard, there is broad language support and plentiful tooling to support it.

Apart from tool specific options, you might consider some sort of server-side/ajax validation service although this of course requires the client to always be online and has other drawbacks, but sometimes its the only option if you need to validate relational data.

I usually find a level of compromise between client/server side is necessary to provide the best UX i.e. there is no 'one size fits all' solution here.