Fixing HTML5 Validation in Rails Forms with Simple Form
While migrating a page from AngularJS to Rails templates, I stumbled on a strange issue: my form skipped HTML5 validation entirely.
At first, I considered handling it manually using the reportValidity() API. But while digging into low-level validation APIs, I discovered the noValidate attribute.
It turns out that Rails forms—when using the simple_form
gem—have novalidate enabled by default. This disables browser-based HTML5 validation.
Since the pages are still under active migration, disabling novalidate globally wasn’t an option. Instead, I disabled it only on the form I was working on—and that solved the issue.
= simple_form_for [@customer, @ad], html: { novalidate: false } do |f|
...