comfy / comfy-bootstrap-form Goto Github PK
View Code? Open in Web Editor NEWRails form builder for Bootstrap 4 markup that actually works!
License: MIT License
Rails form builder for Bootstrap 4 markup that actually works!
License: MIT License
When editing decimal numbers browser will bitch at you because default step is 1
Good idea to set up example in the demo.
Valid form elements generate undefined method '[]' for nil:NilClass
when the form's model does not include an errors
hash.
There are some scenarios when rails forms models are not set from an ActiveRecord model. In these scenarios, unless they emulate the errors
hash produced by ActiveRecord, the rendering of the form element will result in the aforementioned error.
Example:
<%= bootstrap_form_with(model: my_model) do |f| %>
<%= f.text_field :top_level_field %>
<%= f.fields_for :nested_hash, OpenStruct.new(my_model.nested_hash) do |ff| %>
<%= ff.text_field :nested_hash_field %>
<% end %>
<%= f.primary "Save" %>
<% end %>
In this scenario, with vanilla rails form elements, OpenStruct provides all the necessary methods for the nested_hash_field
property to be rendered correctly. Using comfy-bootstrap-form
this will generate an error unless the nested_hash
includes an errors
property.
Suggested Fix
The draw_errors
method in form_builder.rb
already includes a fast-return path if the model is nil
. The criteria should this should be expanded to also return if the errors
hash is not present.
These kinds of errors might not be surfacing correctly.
Need to bump demo app to be Rails 6
Right now I see:
<div class="form-check">
<label class="form-check-label" for="user_misc_1">
<input class="form-check-input" type="checkbox" value="1" name="user[misc][]" id="user_misc_1" />
Foo
</label>
</div>
<div class="radio">
<label for="user_misc_1">
<input type="radio" value="1" name="user[misc]" id="user_misc_1" />
Foo
</label>
</div>
Where it should be:
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="defaultCheck1">
<label class="form-check-label" for="defaultCheck1">
Default checkbox
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios1" value="option1" checked>
<label class="form-check-label" for="exampleRadios1">
Default radio
</label>
</div>
See: https://getbootstrap.com/docs/4.0/components/forms/#default-stacked
See https://getbootstrap.com/docs/4.3/components/forms/#server-side
is-valid
and .valid-feedback
are a thing now. Maybe not really needed as we only care about invalid inputs at that stage.
This is giving me a headache when trying to write an system test that follows best practices (selecting inputs by label text)
:builder
options is passed alonghelp: t(".help.some_field)
that is tied to a view! That would only make sense.test "something" do
is worse that def test_something
as it allows for gibberish names that are hard to scan through.
Options like layout
, label_col
, etc need to be wrapped in bootstrap
option so they can be contained. Like so
module BootstrapForm
class FormBuilder
def initialize(object_name, object, template, options)
@bootstrap_options = options.delete(:bootstrap)
super(object_name, object, template, options)
end
end
end
Same applies to all helpers. Options like help
, etc need to be isolated.
Where did that come from? Never seen that before.
Sticking with conventional way forms display validation errors.
I know we have the custom_control
option to opt out from native components. Unfortunately it does not work with select
currently. See https://getbootstrap.com/docs/4.0/components/forms/#select-menu for details.
Given
<%= f.select :foo, [["Bar", :bar], ["Baz", :baz]], bootstrap: { custom_control: true } %>
When
I check the source code of the generated output.
Then
I expect the class custom-select
to be present on the <select>
.
I'm not sure if this is new with Rails 6, but when I try to load https://localhost:3000/ after running the following, I get a "ActiveRecord::StatementInvalid in BootstrapController#form. Could not find table 'users'" error:
bundle
cd demo
./bin/rails db:setup
./bin/rails s
Remove the .form-control (or maybe the custom-control because I do not see the difference with the default) from the select tags should fix it.
Related to comfy/comfortable-mexican-sofa@70011e4#commitcomment-29569101
For brevity sake let option :label: { text: "foo" }
be the same as label: "foo"
. It's not often you need to add other properties to labels.
form_with
is all we use doing forward. This means dropping support for Rails 5.0. Possibly even 5.1.
For example:
= form.text_field :foo, bootstrap: { error: "It broke" }
See: https://getbootstrap.com/docs/4.3/components/forms/#range
Is that even a thing that Rails would support?
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.