top | item 39479159

(no title)

throwaway60320 | 2 years ago

It's really not that simple.

What about complex validation rules? Do you really think it's user friendly to require them to send the whole form just to tell them "sorry no" 10 times over until they get it right?

What about multi-value selects, potentially with rules? E.g. form field like "choose up to 5 locations in the radius of 10km".

What about form fields like "pick a point on a map"?

Etc. Don't act like every form is 5 simple text inputs.

discuss

order

rmbyrro|2 years ago

Doing validation in the frontend is a bad idea.

You'll have to do in the server, if you're sane.

I bet Retool Forms does in the server.

You're worried the page will refresh with an empty form, if it fails. It's simple, just collect the data and return the form pre-filled using the value attribute, along with the error message.

If you don't want to refresh the page, you could even use something like htmx, which is a LOT simpler than React, but really not necessary for simple form submission.

throwaway60320|2 years ago

Of course you have to validate on the server. That's a given, always.

But you want to provide better UX to the user.

Htmx is not simpler than React. I can't deploy that without a server that knows everything about the frontend. React allows me to decouple. Templates are hell. I lived in it for many years, never again.

hk__2|2 years ago

> Don't act like every form is 5 simple text inputs.

Well to be honest 99% of forms are 5 simple text inputs with a select. What was the last time you had to implement a "choose up to 5 locations in the radius of 10km", really?

> What about form fields like "pick a point on a map"?

Same thing: of course there are rich forms for which you need JS, but they are the exception, not the rule.

_heimdall|2 years ago

React isn't required for client-side validation or non-spec form inputs.

Doing form validation in event handlers for DOM events works very well, and a simple script tag or custom element is all that's needed to build a multi-value select.

throwaway60320|2 years ago

It's not simple. I made multi-page forms with dozens fields where your suggestion would lead to intangible mess of spaghetti code - I know because I worked with the web way before React. Even with the best coding standards and a team of seniors it's just too hard to maintain - and seniors usually don't write forms.

I really don't want to go back to the jQuery days. You do you, but don't say it's easier - it really isn't.

BTW you can just use Preact if you're worried about the bundle size. I do that, it's perfect and just a little performance impact, usually not visible in small apps.

cabalamat|2 years ago

> What about complex validation rules?

I wpould use my server-side form and database library, Bozen[1] to do this.

>

[1]: https://github.com/cabalamat/frambozenapp

throwaway60320|2 years ago

So the user would have to submit the form and be met with 10s of errors? I'd rather tell them immediately.