Primer contains a framework for declaratively building Rails forms. It was designed to meet the following goals:
- Be accessible by default.
- Integrate deeply with Ruby on Rails and its existing form capabilities.
- Follow web standards.
- Adhere to Primer's form interface guidelines.
Accessible by default
Creating accessible forms can be challenging. Forms are a common source of accessibility issues, and can hinder someone from successfully completing and submitting a form. This can be true even for people who do not use assistive technologies.
Primer forms are designed to be accessible by default - i.e. accessible without developer effort - borrowing from Rails' sane defaults philosophy.
For example, Primer forms:
- Automatically associate labels, captions, and validation messages with their inputs.
<fieldset>s where appropriate.
- Focus the first invalid input after submission.
Integrates with Rails
Primer forms augment Rails' battle-tested form capabilties, allowing developers to leverage their existing Rails knowledge. Primer forms delegate HTML generation to Rails, meaning inputs accept the same arguments as their vanilla Rails counterparts. For example, Primer's
#text_field method accepts all the arguments Rails'
#text_field_tag method accepts.
Primer forms are emitted using the familiar
#render method, and wrapped using
#primer_form_with, analogous to Rails'
Follows web standards
What to read next
- Read the getting started guide.
- Take a look at the various form inputs.
- Explore form layout options.
- Compose forms together.
- Include custom validation messages.
- Submit boolean values immediately with toggle switch forms.