• This repository has been archived on 04/Aug/2018
  • Stars
    star
    253
  • Rank 160,776 (Top 4 %)
  • Language
    Ruby
  • License
    Apache License 2.0
  • Created almost 13 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Bootstrap Forms makes Twitter's Bootstrap on Rails easy!

This Project Has Moved!

The bootstrap_forms project has merged with rails-bootstrap-forms and has a new home. Please use the rails-bootstrap-forms gem moving forward. This project is only around for legacy purposes.

Bootstrap Forms

Build Status

Bootstrap Forms is a nice Rails generator that makes working with Bootstrap (by Twitter) even easier on Rails.

Forms with Bootstrap are crowded with additional layout markup. While it's necessary, you shouldn't have to type it every time you create a form! That's why I created Bootstrap Forms.

Bootstrap 2.0 Compliant!

A super special thanks to vincenzor for updating bootstrap_forms to comply with the new methods and features in Twitter Bootstrap 2.0.

To get these new features, ensure you are using bootstrap_forms ~> 2.0.0.

Note/Caution/Warning

There were major changes in the release of version 0.1.0:

  1. The gem name has officially changed from bootstrap-forms to bootstrap_forms to match gem naming conventions. The old gem still exists on rubygems for legacy applications, however, you should update to the new gem as quickly as possible. It's faster and more stable. The old gem is no longer maintained.
  2. form_for is no longer overridden by default. There were multiple users who were concerned that this behavior was ill advised. Instead, a new form helper, bootstrap_form_for has been created. This is in line with other form building libraries.
  3. The gem is now a Rails 3 Engine. As such, Bootstrap Forms will not work in < Rails 3.0. The engine is automatically mounted when including the gem in your Gemfile.

Installation

Add it to your Gemfile:

gem 'bootstrap_forms'

Don't forget to run the bundle command. The gem will add the method bootstrap_form_for for use in your project. This is different from bootstrap_forms < 0.1.0. In previous versions, the default form builders were overridden by default. With backlash from various community members, this is no longer the default.

Be sure to restart your Rails server after installing the gem.

Why?

With Bootstrap, you would need the following code for a form:

/ using HAML
= form_for @model do |f|
  .clearfix
    %label MyLabel
    .input
      = f.text_area :field, :opts => {...}

Using Bootstrap Forms, this is much simpler:

/ using HAML
= bootstrap_form_for @model do |f|
  = f.text_area :field, :opts => {...}

The custom form builder will automatically wrap everything for you. This helps clean up your view layer significantly!

Additional Form Methods

Just when you thought you were done... Bootstrap Forms includes additional form helpers that make life a lot easier! For example, the markup required for a list of checkboxes is quite cumbersome... well, it used to be.

collection_check_boxes

collection_check_boxes behaves very similarly to collection_select:

= f.collection_check_boxes :category_ids, Category.all, :id, :name

You can set the inline option to build inline checkboxes:

= f.collection_check_boxes :category_ids, Category.all, :id, :name, :inline => true

collection_radio_buttons

See description above...

= f.collection_radio_buttons :primary_category_id, Category.all, :id, :name

You can set the inline option to build inline radios:

= f.collection_radio_buttons :primary_category_id, Category.all, :id, :name, :inline => true

check_box

Also supports inline option:

= f.check_box :enabled, :inline => true

radio_buttons

= f.radio_buttons :published, { "Published" => true, "Unpublished" => false }

You can set the :inline option to build inline radios.

= f.radio_buttons :published, { "Published" => true, "Unpublished" => false }, { :inline => true }

You can set radio options by passing a hash instead of a value:

= f.radio_buttons :published, { "Published" => true, "Unpublished" => {:value => false, :disabled => true} }

Ruby 1.8 doesn't guarantee hashes are ordered. If you care, pass in nested arrays or ActiveSupport::OrderedHash.

Uneditable Input

Bootstrap Forms adds another helper method that generates the necessary markup for uneditable inputs:

= f.uneditable_input :name

yields:

<div class="clearfix">
  <label for="organization_name">Organization Name</label>
  <div class="input">
    <span class="uneditable-input">The Variety Hour</span>
  </div>
</div>

Submit Tag

Bootstrap Forms also adds a default actions panel when you call f.actions:

= f.actions

generates:

<div class="actions">
  <input type="submit" value="..." class="btn primary" />
  <a href="..." class="btn">Cancel</a>
</div>

You can skip the cancel button by passing the :include_cancel button a false value.

Pretty swell if you ask me.

Adding More Options

You can add as many options to any form helper tag. If they are interpreted by Bootstrap Forms, they are interpreted and rendered in the output. If not, they are passed along as values to the final HTML form object.

Form Options

Name Description Usage Default
summary_errors Show summary errors at the top = bootstrap_form_for @thing, summary_errors: false true

Field Options

Name Description Usage
help_inline Add inline help text = f.text_field :name, :help_inline => 'help me!'
help_block Add block help text (below) = f.text_field :name, :help_block => 'help me!'
error Styles the field as error (red) = f.text_field :name, :error => 'This is an error!'
success Styles the field as success (green) = f.text_field :name, :success => 'This checked out OK'
warning Styles the field as warning (yellow) = f.text_field :name, :warning => 'Take a look at this...'
prepend Adds special text to the front of the input = f.text_field :name, :prepend => '@'
append Adds special text at the end of the input = f.text_field :name, :append => '@'
append_button Adds the given button to the end of the input. The value is a hash.
:label is the button label
:icon adds an icon before the label
:class has a default value of 'btn'
:type has a default value of 'button'
Any other entries are passed directly to Rails's tag helper. Pass an array of hashes to append multiple buttons.
= f.text_field :name, :append_button => { :label => 'Button label', :icon => 'icon-plus', :type => 'button' }
label Customize the field's label. Pass false to have no label. = f.text_field :name, :label => 'Other name'
control_group Pass false to remove the control group and controls HTML, leaving only the label and input. = f.text_field :name, :control_group => false
:required => false Pass false to ignore presence validation checks that add a required attribute on the generated element. = f.text_field :name, :required => false

Internationalization/Custom Errors

As of 1.0.2, bootstrap_forms supports I18n! More support is being added, but you can change the error header and cancel button like this:

# config/locales/en.yml
en:
  bootstrap_forms:
    errors:
      header: 'Your %{model} is wrong!'
    buttons:
      cancel: 'Forget it!'

Obviously you can also change to a different lang.yml file and use the same syntax.

Nested Forms

Bootstrap Forms works with Ryan Bates' nested_form out of the box. Just add nested_form to you Gemfile and bootstrap_forms will automatically add a builder for you:

= bootstrap_nested_form_for @model do |f|

Contributing

I'm pretty dam active on github. Fork and submit a pull request. Most of my pull requests are merged the same day. Make sure you:

  • Squash into a single commit (unless it makes sense to have multiple commits)
  • Test/Spec the changes
  • Document your changes

License & Authors

Copyright 2012-2013 Seth Vargo <[email protected]>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

More Repositories

1

go-envconfig

A Go library for parsing struct tags from environment variables.
Go
1,037
star
2

ratchet

A tool for securing CI/CD workflows with version pinning.
Go
771
star
3

go-password

A Golang library for generating high-entropy random passwords similar to 1Password or LastPass.
Go
642
star
4

go-retry

Go library for retrying with configurable backoffs
Go
631
star
5

go-limiter

A supersonic rate limiting package for Go with HTTP middleware.
Go
526
star
6

vault-on-gke

Run @HashiCorp Vault on Google Kubernetes Engine (GKE) with Terraform
HCL
497
star
7

go-githubactions

Go SDK for GitHub Actions - easily author GitHub Actions in Go
Go
434
star
8

vault-secrets-gen

A Vault secrets plugin for generating high entropy passwords and passphrases.
Go
338
star
9

go-signalcontext

Create Go contexts that cancel on signals.
Go
260
star
10

vault-kubernetes-authenticator

An app and container for authenticating services to @HashiCorp Vault's via the Kubernetes auth method
Go
205
star
11

powify

Powify is an easy-to-use wrapper for 37 signal's pow
Ruby
189
star
12

vault-kubernetes-workshop

Steps and scripts for running @HashiCorp Vault on @GoogleCloudPlatform Kubernetes
Shell
154
star
13

chef-sugar

143
star
14

terraform-provider-googlecalendar

A @HashiCorp Terraform provider for managing Google Calendar events.
Go
136
star
15

go-diceware

Golang library for generating passphrases via the diceware algorithm.
Go
99
star
16

secrets-in-serverless

A collection of examples for doing secrets management in serverless lambda or cloud functions.
Go
91
star
17

vault-init

Automate the initialization and unsealing of @HashiCorp Vault on @GoogleCloudPlatform
Go
82
star
18

atlantis-on-gke

A set of @HashiCorp Terraform configurations for running Atlantis on @GoogleCloud GKE
HCL
68
star
19

vault-token-helper-osx-keychain

An example @HashiCorp Vault token helper for Mac OS X Keychain.
Go
65
star
20

vault-demo

Walkthroughs and scripts for my @HashiCorp Vault talks
Shell
65
star
21

terraform-provider-filesystem

A @HashiCorp Terraform provider for interacting with the filesystem
Go
62
star
22

hashicorp-installer

Script and Docker container for installing @HashiCorp tools
Shell
50
star
23

vault-auth-slack

A @HashiCorp Vault plugin for authenticating and receiving policies via Slack.
Go
50
star
24

cleanroom

(More) safely evaluate Ruby DSLs with cleanroom
Ruby
44
star
25

go-cache

Cache implementations in Go, with support for generics.
Go
44
star
26

cloud-run-docker-mirror

Mirror images from one Docker repository to another, as a service.
Go
38
star
27

vault-puppet

Using @HashiCorp Vault with Puppet
Shell
36
star
28

gcs-cacher

Utility for saving and restoring caches backed by Google Cloud Storage.
Go
35
star
29

base64-is-not-encryption

Demo repo showing Kubernetes secrets being sad
Shell
31
star
30

fast

A CLI tool for testing download speed using Netflix's fast.com service.
Go
27
star
31

isbndb

Ruby ISBNdb is a simple, Ruby library that connects to ISBNdb.com's Web Service and API.
Ruby
26
star
32

go-redisstore

Go rate limiter interface for Redis
Go
18
star
33

terraform-provider-berglas

A Terraform provider for Berglas
Go
17
star
34

vault-fluentd-configurations

Fluentd configurations for @HashiCorp Vault
17
star
35

go-gcpkms

Wrappers around Google Cloud KMS that implement Go's crypto.Signer and crypto.Verifier interfaces.
Go
16
star
36

now-or-never-resource-optimizer

A resource optimizer for Now or Never, written in Go, compiled to WASM, run in the browser.
Go
16
star
37

go-gcslock

A Go library for acquiring a forward-looking lock in Google Cloud Storage.
Go
14
star
38

terraform-cloud-run-demo

Sample Terraform configurations for creating a publicly accessible Cloud Run service
HCL
13
star
39

vault-token-helper-gcp-kms

A @HashiCorp Vault token helper for encrypting/decrypting via @GoogleCloudPlatform KMS
Go
12
star
40

kubecon18

Scripts and demo for my Kubecon 2018 talk
HCL
10
star
41

go-malice

A malicious package to demonstrate the importance of software supply chain security.
Go
7
star
42

zapw

Finds common errors for the zap logger using static analysis.
Go
7
star
43

powify.dev

The official web-management tool for Powify
Ruby
7
star
44

envjector

Exec a subprocess with an environment specified in a file. Like env, but a single static binary across multiple operating systems.
Go
6
star
45

go-hello-githubactions

Sample code for GitHub Actions with Go
Dockerfile
5
star
46

gcpkms-rand

Use Google Cloud KMS as an io.Reader and rand.Source.
Go
5
star
47

serverless-secrets-talk

Demo script and code for secrets in serverless talk.
Go
4
star
48

envserver

A webserver that prints the environment it was spawned in
Go
3
star
49

community-zero

3
star
50

spellingbee

A small Go program to generate solutions to the NYT Spelling Bee.
Go
2
star
51

cloud-run-empathy-sms-hello-world

Sample code for sending text messages via Twilio on Cloud Run.
Python
2
star
52

go-redisstore-opencensus

Go rate limiter interface for Redis with instrumentation.
Go
2
star
53

chatty

Go
1
star
54

terraform-secret-manager-demo

HCL
1
star
55

terraform-0.13-google-cloud-demo

Sample for Terraform 0.13 unique features on Google Cloud
HCL
1
star
56

docker-postgres-pgaudit

A Docker image for postgres with pgAudit available
Makefile
1
star