In some projects we use Simple Form Show archive.org snapshot to write boring forms more quickly.
Important
Work on this lesson in
buildermode.
Learning goals
- You can explain what Simple Form does for a form, where it pays off, and where plain form helpers are the better choice.
- You can configure Simple Form's generated HTML to match a project's markup, e.g. with its Bootstrap wrapper configuration.
- You can write forms with Simple Form's input types and options.
- You can extend Simple Form with a custom input type.
Resources
Read what's new to you, skim what's familiar, skip what you already master. Stop when you can meet the learning goals.
Your agent can also generate an overview, a tutorial or an explanation for anything here, tailored to what you already know. Just ask.
- ▶️ "Formulare mit SimpleForm" — internal talk (in our library), slides
- 📄 Simple Form README Show archive.org snapshot — the manual; the wiki Show archive.org snapshot has recipes for custom inputs and wrappers
- 📄 How our projects configure and extend Simple Form, e.g. in Studyflix:
simple_form_bootstrap.rbandsimple_form_helper.rb(internal)
Exercises
Use Simple Form
Tip
Make sure that the Simple Form Bootstrap initializer is configured for the correct Bootstrap version Show archive.org snapshot . Version 5.1 of the gem currently gives you an outdated configuration for Bootstrap 4.
Rewrite two boring forms in MovieDB so they use Simple Form.
Expect some pain to initially configure Simple Form to use the HTML structure of your MovieDB. After that your forms should be much shorter than before.
Extend Simple Form
Extend your Simple Form integration with a new input type :money that may be used like this:
= form.input :amount, as: :money
Money inputs differ from regular numeric inputs:
- After the input there is an Euro symbol ("€") (it's not part of the input value)
- The input value should always be rounded to two digits precision.
- E.g. when the money amount is
2, the value should display as2.00. When the amount is3.5it should display as3.50. - The rounding only needs to be applied when Rails renders the input. It does not need to be applied while the user is typing in a new value.
- E.g. when the money amount is