Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bootstrap Form Builder #42

Closed
msheakoski opened this issue Jan 28, 2012 · 3 comments
Closed

Bootstrap Form Builder #42

msheakoski opened this issue Jan 28, 2012 · 3 comments

Comments

@msheakoski
Copy link

I wrote a bootstrap_form_for builder that outputs HTML for use with Bootstrap 2.0's .form-horizontal or .form-vertical styles.

https://gist.github.com/1695087

It follows Bootstrap's convention of adding the .error class to the .control-group fieldset and overrides Rail's default error wrapping behavior. It does not conflict with ActionView::Base.field_error_proc so non-bootstrap forms function normally.

This gem seems like a good home for a bootstrap form builder so I thought I would share what I have if you wish to use it as a starting point. It obviously is very basic and needs refinement but it gets the job done.

<%= bootstrap_form_for @user, html: {class: 'form-horizontal'} do |f| %>
  <legend>Create an Account</legend>

  <%= f.control_group :email do %>
    <%= f.email_field :email %>
  <% end %>

  <%= f.control_group :password do %>
    <%= f.text_field :password %>
    <p class="help-block">Must be at least 6 characters</p>
  <% end %>

  <%= f.control_group :full_name do %>
    <%= f.text_field :full_name %>
  <% end %>

  <%= field_set_tag nil, class: 'form-actions' do %>
    <%= button_tag 'Create account', type: 'submit', class: 'btn primary' %>
    <%= link_to 'Cancel', root_path %>
  <% end %>
<% end %>
@seyhunak
Copy link
Owner

Thanks for your contribution. It looks like good starting point so I urgently need a robust Formbuilder (for themed generator). I'll implement that (watching gist) if I can catch some free time.

@damireh
Copy link

damireh commented Jan 28, 2012

👍

@msheakoski
Copy link
Author

I forgot to demonstrate in the example, but you can also do custom labels with:

<%= f.control_group :full_name, label: 'Your first and last name' do %>
  <%= f.text_field :full_name %>
<% end %>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants