bootstrap-ruby / bootstrap_form Goto Github PK
View Code? Open in Web Editor NEWOfficial 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
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
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
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
f.radio_buttons_collection :number, [['One', 1], ['Two', 2]], :last, :first, checked: 1
does not result in 'One' being checked by default.
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.
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 %>
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.
search_field
support currently doesn't exist and would be nice if possible.
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.
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?
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.
Also, this feature might coincide with the ability to mark fields with certain "Validation States" (http://getbootstrap.com/css/#forms-control-states):
.has-error (this already works)
.has-warning
.has-success
fields_for helper is missing
Hi guys,
Seems, 'static_control' dosen't work.
Form:
<%= bootstrap_form_for( ... ) do |f| %>
<%= f.static_control :email %>
...
<% end %>
it's return:
undefined method `static_control' for #BootstrapForm::FormBuilder:0x000000073a5780
Thanks,
Siarhei
<%= 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...
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.
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'
When using the form.email_field method, it produces an input field with type="text", when it should use type="email".
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
Readme says the layout can be overridden per field like so:
<%= f.text_field :feet, layout: :inline %>
It doesn't look like there's anything in form_group() that handles this, only layout: :horizontal.
It would be nice if we add support for global config options to avoid the necessity of defining them all the time.
The control_group method calls object.errors
, which will fail if object is nil, or if object doesn't respond to errors.
This is valid Rails form syntax, which fails under bootstrap_form_for:
= f.fields_for :options do |builder|
= builder.text_field :color
= builder.text_field :size
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|
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 %>
Did this break the f.submit default text option.
I am getting wrong number of options now when just using f.submit
@potenza can i add me on gemspec's author list?
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
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
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'.
Is that possible? I couldn't get it to work. E.g.
= f.select :active, [['Yes', 1],['No', 0]], help: 'Do you want to enable the feature?'
Not a great example, cause a radio button is probably better here, but you get the idea.
https://github.com/bootstrap-ruby/rails-bootstrap-forms#help-text
I am getting the error - wrong number of arguments (0 for 1..2) when using the code in this gist file: https://gist.github.com/ambshar/9399729
It fails on f.submit
I am using rails 4.0.1, ruby 2, bootstrap_form 2.0.1
I put *= require rails_bootstrap_forms in my application.css file
Allow bootstrap to be used with annoynmous models with bootstrap_form_tag which doesn't rely on form_for, but instead form_tag
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!
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>
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
Hi there
Is there any plan to support datetime_field, week_field etc?
Thanks
Tobin
A check_box field with validation errors eg.
f.check_box :terms_of_service
and
validates_acceptance_of :terms_of_service, message: 'tick the checkbox!'
will not render the correct error html when invalid.
Are there major differences in bootstrap between these versions?
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
The primary
helper doesn't seem to work. I get this error when trying to use it:
undefined method `primary' for #<BootstrapForm::FormBuilder:0x37dc1f0>
Could you please support the popular country_select
gem?
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>
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.
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)?
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.
f.check_box :field
produces the same even if i have errors[:field] << 'error'
in model
<%= 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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.