Coder Social home page Coder Social logo

bootstrap-ruby / bootstrap_form Goto Github PK

View Code? Open in Web Editor NEW
1.6K 1.6K 351.0 4.58 MB

Official repository of the bootstrap_form gem, a Rails form builder that makes it super easy to create beautiful-looking forms using Bootstrap 5.

License: MIT License

Ruby 99.90% CSS 0.10%
bootstrap rails rails-form-builder ruby

bootstrap_form's People

Contributors

atipugin avatar baldwindavid avatar carloslopes avatar charliewinkwaves avatar desheikh avatar donv avatar duleorlovic avatar gbh avatar hab avatar jdufresne avatar johrstrom avatar jsaraiva avatar koenpunt avatar krsyoung avatar laserlemon avatar lcreid avatar madebydna avatar mattbrictson avatar olleolleolle avatar parkeryoung avatar potenza avatar qcam avatar rzane avatar scottswezey avatar simmerz avatar thimo avatar thomassevestre avatar ttanimichi avatar uwekubosch avatar wingrunr21 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bootstrap_form's Issues

Add option to override form style on a field by field or group basis

Ability to do:

= bootstrap_form_for(@user, style: :horizontal) do |f|
  =f.textarea :normal
  =f.textarea :special, left: 'col-md-6', right: 'col-md-6'

or

= bootstrap_form_for(@user, style: :horizontal) do |f|
  =f.textarea :normal
  =f.layout(style :inline, left: 'col-md-6', right: 'col-md-6') do
    =f.textarea :special

Add bootstrap_form_tag

Allow bootstrap to be used with annoynmous models with bootstrap_form_tag which doesn't rely on form_for, but instead form_tag

"hide_label: true" on select element does not update the element's parent div class to col-sm-12.

Hello! Really digging this gem so far, but I have a question:

# in my view:
f.select :parent_id, options_for_parents(@page), {}, hide_label: true
<!-- Generated HTML from the view: -->
<div class="form-group">
  <label class="sr-only col-sm-2 control-label" for="page_parent_id">Hoofdniveau</label>
  <div class="col-sm-10">
    <select class="form-control" id="page_parent_id" name="page[parent_id]">
    ...
    </select>
  </div>
</div>

I was wondering if there is a way with the current codebase to circumvent the behaviour so that whenever I set hide_label: true, it will change the select parent's class to col-sm-12 instead of col-sm-10. I can do it with a few lines of JavaScript, but would prefer it in Ruby.

This is what I would like to end up with:

<div class="form-group">
  <!-- The label may be removed in this case -->
  <div class="col-sm-12">
    <select class="form-control" id="page_parent_id" name="page[parent_id]">
    ...
    </select>
  </div>
</div>

Validation errors

<%= f.alert_message "Please fix the errors below." %>

How do you use this in a form partial. It seems that the message is hard coded...

My update and create actions would have same error message

Nice gem by the way...

Label dosen't work in select field

Hi Guys,

I try to create select field by

f.select :year, options_for_select((1996..2014).to_a.reverse), :label => 'Some label'

But label displays as Year and not as 'Some lablel'.

Allow block for check_box label

You might consider allowing this:

<%= f.check_box :accepted_terms do %>
  I have read and understood the <%= link_to "General Business Terms and Conditions", :terms, target: "_blank" %> and accept them.
<% end %>

instead of this:

<%= f.check_box :accepted_terms, label: "I have read and understood the #{link_to("General Business Terms and Conditions", :terms, target: "_blank")} and accept them.".html_safe %>

DateTime Appearance

Great little library, thanks!

Is this how the datetime select is supposed to look?

image

Just wondering, I'm looking to tweak this to bring it on one line.

Nested inline datetime_select on a horizontal form

Thanks for making such a great gem! I have a quick question.
I have a horizontal form but inside this form I have a datetime_select option that I want inline. Currently each field for datetime_select is put to a new row and it takes up too much space. Can I maintain a horizontal form and keep my datetime_select fields inline?

Example
<%= bootstrap_form_for(@book_reviews, style: :horizontal) do |f| %>
<%= f.datetime_select :submission_date %>
<% end %>

Maybe a solution like the check boxes and radios would work, but its not implemented I think.. I tried this also...

<%= bootstrap_form_for(@book_reviews, style: :horizontal) do |f| %>
<%= f.datetime_select :submission_date, inline: true %>
<% end %>

Thanks for your time!

Implement support for nested forms

From bootstrap_forms README:

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|

wrong number of arguments (5 for 4)

This seems to be a similar issue to #25

This error is happening for me with Rails 4.1.0.beta1 + bootstrap_form 2.0.1. I am using Bootstrap 3.

This is a gist of my form: https://gist.github.com/lurkermike/8216402

The error message is: "wrong number of arguments (5 for 4)" at the line which contains the bootstrap_form_for call.

I've tried stripping down the form to a single label and text field but the error persists.

Any help would be appreciated.

Rails 4.1 support

The released version still doesn't support 4.1. The 4.1.0 branch is not merged and last updated more than 2 months ago.

Move to central organisation?

Hi!

I am the maintainer of three gems similar to this one that make it easier to use Twitter Bootstrap in Ruby projects (https://github.com/krautcomputing/rails-bootstrap-navbar, https://github.com/krautcomputing/bootstrap-navbar, https://github.com/krautcomputing/middleman-bootstrap-navbar).

I was thinking about moving all those gems to a separate organisation (like "bootstrap-ruby") and wanted to get some feedback from other maintainers of similar gems (and the community at large) if that makes sense and if we could use this to make it easier for people to find gems to work with Bootstrap in Ruby (Rails, Sinatra, etc.)
I think it would also invite other people to contribute to those projects if they were united in a central organisation.

What do you think?
Would you be willing to move this repo to such an organisation as well?

Error when trying to set label text for field in bootstrap_form_tag

<%= bootstrap_form_tag(:url => register_path, :html => {:role => "form", :remote => true }) do |f| %>
    <%= f.password_field :password_confirmation, label: "Confirm Password" %>
    <%= f.submit "Sign Up" -%>
<% end %>

This throws an error can't convert Symbol into Integer inside form_builder.rb:convert_form_tag_options

radio_button generates incorrect markup for bootstrap css

Bootstrap expects radio buttons to be nested inside a <div class='radio'>, similar to checkboxes.

The check_box() method in this gem handles this and generates markup that works with bootstrap, but radio_button does not.

Is this intentional? I'm probably missing something.

Readme correction

The read me says use an option called "layout" but in fact the option name is "style"

 bootstrap_form_for(@thing, style: :horizontal) do |f|

 end

bootstrap_form_tag support

Can we have this? I'm trying to use bootstrap_form_for with a string, but I'm having some errors when using checkboxes.

<%= bootstrap_form_for("search") do |f| %>
<%= f.check_box "Anything" %>
<% end %>  

Returns:

undefined method `human_attribute_name' for NilClass:Class at form_builder.rb:65

Label dosen't work in select field #36

This is still a issue:

= f.select :asset_type, options_for_select(["BES Cyber System", "Associated Protected Cyber Asset", "Associated Electronic and Physical Access Control and Monitoring Systems"]), include_blank: true

label shown is;

Asset type

wrong number of parameters

Hi,
I'm trying to use bootstrap_form_for, using the given example (just modified @user to my model and updated all required fields).
For some reason i'm getting an error "wrong number of parameters (4 for 5)" on the first line of the form (bootstrap_form_for(@item....) and I cannot seem to find the reason.
I'm using rails 4 + Bootstrap 3.

Any help would be appreciated,
Thanks,
Roy

Overriding label text on FIELD_HELPERS with bootstrap_tag_for throws an exception

I'm using

gem 'bootstrap_form', git: 'git://github.com/bootstrap-ruby/rails-bootstrap-forms.git', branch: 'nested_form_support'

and

<%= bootstrap_form_tag url: sessions_path do |f| %>
  <%= f.email_field :email, label: "Custom" %>

throws TypeError: no implicit conversion of Symbol into Integer at line 214 of helper.rb

The problem is that form_group_builder expects options[:label] to be a string. However, acts_like_form_tag == true in bootstrap_form_tag, so form_group_builder calls convert_form_tag_options at line 196 which expects options[:label] to be a Hash.

Using Control-group

In previous version was able to use control group to allow multi fields on one line in horizontal from using :control_group => false.
Has this feature not been added to new combined version? I can't seem to get it to work.
previous version with old bootstrap

<%= f.label :fmi, "Name (First Last)", :class => 'control-label' %>
<%= f.text_field :fmi, :class => 'span2', :control_group => false, :label => false %> <%= f.text_field :lastname, :class => 'span2', :control_group => false, :label => false %>

f.primary doesn't work

The primary helper doesn't seem to work. I get this error when trying to use it:

undefined method `primary' for #<BootstrapForm::FormBuilder:0x37dc1f0>

Wrong version on rubygems

Hey,

i reinstalled the gem from rubygems and there are the following code:

def primary(name)
  submit name, class: 'btn btn-primary'
end

I miss the 2. option parameter of the function.

Cheers,
Michael

Bootstrap 3

Are there major differences in bootstrap between these versions?

Form :style option

This is very nit-picky, but using the option name of :style for the layout is a little confusing since it is an actual attribute that can be added to HTML elements...hopefully not often these days :)
Just a thought that :layout might be a good option name for this functionality.

Are :left and :right the best names?

This may have already been discussed, but has there been any thought to changing the names of the :left and :right options? Right now they are only used for the horizontal layout so they make pretty good sense. That being said, the label won't always be on the left and the input not always on the right. I'm wondering if these should be called something like :label_container and :input_container or :label_width and :input_width. This might allow in the future being able to pass in options for these containers for vertical and inline forms as well. This is a bit complicated by the label tag being the actual container in Bootstrap, but I just wanted to throw it out there for discussion if it hasn't already been discussed.

undefined method 'html_safe' when looping inside of control group

When using bootstrap_form (v0.3.2), the snippet below

  <%= f.control_group do %>
    <% 3.times do %>
      <%= f.radio_button :attribute, 0, label: "Button" %>
    <% end %>
  <% end %>

results in the error undefined method 'html_safe' for 3:Fixnum.

A similar error occurs when iterating over the items in an array, except that the error is on the Array instead of a Fixnum.

This error does not occur if there is an empty line before the control group's <% end %>:

  <%= f.control_group do %>
    <% 3.times do %>
      <%= f.radio_button :attribute, 0, label: "Button" %>
    <% end %>

  <% end %>

Rails 4.0.4: ActionView::Template::Error: Can't parse CSS

Just upgraded to Rails 4.0.4 and I am getting this error:

ActionView::Template::Error:
       Error: Can't parse CSS: Unexpected { in decls at line 4:10 in rails_bootstrap_forms.css

Rails 4.0.4 includes an updated version of sass-rails, which may be the culprit. Here are my gem versions:

  * sass (3.2.16)
  * sass-rails (4.0.2)

Perhaps the problem is that rails_bootstrap_forms.css has the .css file extension, even though the contents of the file seem to be using SCSS syntax (nesting)?

accept "label: false" as alternative to render field without a label

Would you be open to adding support for this option ?

<%= f.text_area :comment, label: false, placeholder: 'Leave a comment...' %>

Without reading the docs, I intuitively tried this first before realizing the correct approach is using label: :none and I believe other people might try doing the same.

I'd be happy to submit a pull request that doesn't break the existing API.

Add global config options

It would be nice if we add support for global config options to avoid the necessity of defining them all the time.

Block for check_box label is not working in Rails 4

the example from the main page is not working in Rails 4:

<%= bootstrap_form_for @user, style: :horizontal, right: "col-sm-4" do |f| %>
  <%= f.form_group :agreement_form do %>
    <%= f.check_box(:agreement_form) do %>
      I agree to the Terms of Service
    <% end %>
  <% end %>
<% end %>

produces check box with label: 'Agreement form'

<div class="col-sm-4">
  <div class="checkbox">
    <label for="user_agreement_form">
      <input name="user[agreement_form]" type="hidden" value="0">
      <input id="user_agreement_form" name="user[agreement_form]" type="checkbox" value="1"> 
      Agreement form
    </label>
  </div>
</div>

datetime_field etc

Hi there

Is there any plan to support datetime_field, week_field etc?

Thanks

Tobin

Nested Form Support Not Working in Master

I cannot get bootstrap_nested_form_for to work anymore.
I have attached my backtrace.

@wingrunr21 have you gotten it to work since the rebase?

I tried to revert to various versions that used to work, eg: e70c5c5

However i see that even that ref includes changes from @potenza as recent as April 1st. So I'm not sure how to revert to a working version.

ActionView::Template::Error (wrong number of arguments (5 for 4)):
    1: =bootstrap_nested_form_for(@ast_queue, bsf_opts) do |f|

A ActionView::Template::Error occurred in ast_queues#edit:

  wrong number of arguments (5 for 4)
  /Users/k3leland/.rvm/gems/ruby-1.9.2-p290/bundler/gems/rails-bootstrap-forms-ef1d6f7535a0/lib/bootstrap_form/form_builder.rb:18:in `initialize'

-------------------------------
Backtrace:
-------------------------------

  /Users/k3leland/.rvm/gems/ruby-1.9.2-p290/bundler/gems/rails-bootstrap-forms-ef1d6f7535a0/lib/bootstrap_form/form_builder.rb:18:in `initialize'
  actionpack (3.2.17) lib/action_view/helpers/form_helper.rb:962:in `new'
  actionpack (3.2.17) lib/action_view/helpers/form_helper.rb:962:in `instantiate_builder'
  actionpack (3.2.17) lib/action_view/helpers/form_helper.rb:377:in `form_for'
  haml (4.0.5) lib/haml/helpers/action_view_mods.rb:139:in `form_for_with_haml'
  haml (4.0.5) lib/haml/helpers/action_view_xss_mods.rb:28:in `form_for_with_haml_xss'
  /Users/k3leland/.rvm/gems/ruby-1.9.2-p290/bundler/gems/rails-bootstrap-forms-ef1d6f7535a0/lib/bootstrap_form/helper.rb:23:in `block in bootstrap_form_for'
  /Users/k3leland/.rvm/gems/ruby-1.9.2-p290/bundler/gems/rails-bootstrap-forms-ef1d6f7535a0/lib/bootstrap_form/helper.rb:36:in `temporarily_disable_field_error_proc'
  /Users/k3leland/.rvm/gems/ruby-1.9.2-p290/bundler/gems/rails-bootstrap-forms-ef1d6f7535a0/lib/bootstrap_form/helper.rb:22:in `bootstrap_form_for'
  /Users/k3leland/.rvm/gems/ruby-1.9.2-p290/bundler/gems/rails-bootstrap-forms-ef1d6f7535a0/lib/bootstrap_form/helpers/nested_form.rb:15:in `bootstrap_nested_form_for'
  app/views/ast_queues/_form.html.haml:1:in `_app_views_ast_queues__form_html_haml__1923276433556906628_70181232724740'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.