DEV Community

loading...
Cover image for Introducing Optimism: realtime remote form validation for Rails

Introducing Optimism: realtime remote form validation for Rails

leastbad profile image leastbad ・1 min read

I'm proud to announce the public release of Optimism, a new Ruby on Rails gem that makes it easy to add realtime validation error messages to your applications.

When a model validation error prevents an update from succeeding, Optimism builds a list of issues that must be resolved. This list is broadcast to the browser over a websocket connection, and the live document is changed to show the necessary validation hints. No page refreshes are required and the entire process happens faster than you can blink.

Optimism injects text content, CSS class updates and even DOM events into your page. It has no client-side scripting requirements beyond a dependency to the awesome CableReady library. It automatically handles multi-level nested forms and plays well with other technologies, such as Turbolinks.

You can try a live demo right now.

Full documentation is available here. The project lives on Github here and you can get help via Discord here.

Discussion (4)

pic
Editor guide
Collapse
ben profile image
Ben Halpern

I’m not totally sure I follow, what is this doing differently than AJAX?

Collapse
leastbad profile image
leastbad Author • Edited

Probably best to take a quick read through optimism.leastbad.com/quick-start but while the form itself is submitted via UJS (Ajax / remote=true) out of the box there is nothing in Rails to handle in-line validation errors.

I promise you that there's a lightbulb/aha! moment in your immediate future. Give it a try.

(This is of the "holy crap, I didn't have to write any code" variety.)

Collapse
leastbad profile image
leastbad Author

Hey Ben, did you ever get to try Optimism? Still patiently waiting to offer any help.

The only thing that's changed since my last note is how popular it's become. ;)

Collapse
leastbad profile image
leastbad Author

Let me know if you have any issues getting it fired up; it should take <2m. I genuinely want you to love it.