https://github.com/mjc-gh/form_buildable
Declaratively build FormBuilder classes in Rails. Goes great with TailwindCSS!
https://github.com/mjc-gh/form_buildable
Last synced: 29 days ago
JSON representation
Declaratively build FormBuilder classes in Rails. Goes great with TailwindCSS!
- Host: GitHub
- URL: https://github.com/mjc-gh/form_buildable
- Owner: mjc-gh
- License: mit
- Created: 2024-05-18T22:20:39.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-08-26T00:09:56.000Z (about 1 year ago)
- Last Synced: 2025-09-01T21:45:29.290Z (about 1 month ago)
- Language: Ruby
- Homepage:
- Size: 33.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: MIT-LICENSE
Awesome Lists containing this project
README
# FormBuildable
[](https://github.com/mjc-gh/form_buildable/actions/workflows/actions.yml)
Declaratively build
[FormBuilder](https://api.rubyonrails.org/classes/ActionView/Helpers/FormBuilder.html)
classes in Rails. Goes great with TailwindCSS!## Usage
```ruby
module ApplicationHelper
include FormBuildabledefine_form_builder :default do
html_classes do
button {
"inline-flex items-center justify-center rounded border shadow-sm font-medium px-4 py-2 text-sm "\
" border-transparent text-white bg-blue-600 md:text-base lg:text-lg hover:bg-blue-800 "
}form { "space-y-4" }
field { "flex flex-col gap-2" }check_box_input { "w-6 h-6 text-blue-600 bg-gray-100 border-gray-300 rounded" }
check_box { "flex gap-2 items-center" }
check_box_label { "text-md" }input { "rounded-lg border-slate-300 p-2 text-slate-900 " }
error_container { "flex justify-start" }
error { "text-sm text-red-700 font-bold whitespace-pre" }
end
enddefine_form_builder :inline do
# some other classes...
end
end
```Now use in a view with `default_form_with` or `default_form_for`
```erb
<%= default_form_with model: @user, url: registrations_path do |form| -%>
<%= form.email_field :email -%>
<%= form.check_box :accepted_terms -%>
<%= form.button -%>
<% end -%>
```Will produce some HTML like:
```html
Accepted terms
Create User
```And when there is an error, the model's errors are automatically added
to the markup```html
Address
Address is invalid
Accepted terms
Accepted terms must be accepted
Create Email
```
## TODO
So much! Maybe?
- Radio buttons, selects, and other fields
- Customize HTML of wrapper methods
- Customize error and label HTML placement with the inputs
- Form hints, placeholders, and more I18n customizations
- Document other new form builder methods like `error_tag` and `field`## Installation
Add this line to your application's Gemfile:```ruby
gem "form_buildable"
```And then execute:
```bash
$ bundle
```Or install it yourself as:
```bash
$ gem install form_buildable
```## Contributing
Contribution directions go here.## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).