Skip to content

Commit

Permalink
Added examples for check box /radio button collections with inline er…
Browse files Browse the repository at this point in the history
…rors to the README.md

Fixes #655
  • Loading branch information
donv committed Sep 12, 2023
1 parent 8ff07f8 commit 61fc37a
Show file tree
Hide file tree
Showing 40 changed files with 46 additions and 9 deletions.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,8 @@ error will be displayed below the field. Here's an example:
```erb
<%= bootstrap_form_for(@user_with_error) do |f| %>
<%= f.email_field :email %>
<%= f.collection_radio_buttons :misc, Skill.all, :id, :name %>
<%= f.collection_check_boxes :preferences, [[1, 'Good'], [2, 'Bad']], :first, :second %>
<%= f.fields_for :address do |af| %>
<%= af.text_field :street %>
<% end %>
Expand All @@ -1438,6 +1440,31 @@ Generated HTML:
<input class="form-control is-invalid" id="user_email" name="user[email]" required="required" type="email" value="steve.example.com">
<div class="invalid-feedback">is invalid</div>
</div>
<div class="mb-3">
<label class="form-label" for="user_misc">Misc</label>
<div class="form-check">
<input checked class="form-check-input is-invalid" id="user_misc_1" name="user[misc]" type="radio" value="1">
<label class="form-check-label" for="user_misc_1">Mind reading</label>
</div>
<div class="form-check">
<input class="form-check-input is-invalid" id="user_misc_2" name="user[misc]" type="radio" value="2">
<label class="form-check-label" for="user_misc_2">Farming</label>
<div class="invalid-feedback">is invalid</div>
</div>
</div>
<input autocomplete="off" id="user_preferences" name="user[preferences][]" type="hidden" value="">
<div class="mb-3">
<label class="form-label" for="user_preferences">Preferences</label>
<div class="form-check">
<input checked class="form-check-input is-invalid" id="user_preferences_1" name="user[preferences][]" type="checkbox" value="1">
<label class="form-check-label" for="user_preferences_1">Good</label>
</div>
<div class="form-check">
<input class="form-check-input is-invalid" id="user_preferences_2" name="user[preferences][]" type="checkbox" value="2">
<label class="form-check-label" for="user_preferences_2">Bad</label>
<div class="invalid-feedback">is invalid</div>
</div>
</div>
<div class="mb-3">
<label class="form-label" for="user_address_attributes_street">Street</label>
<input class="form-control is-invalid" id="user_address_attributes_street" name="user[address_attributes][street]" type="text" value="Bar">
Expand Down Expand Up @@ -1508,6 +1535,7 @@ Which outputs:
<ul class="rails-bootstrap-forms-error-summary">
<li>Email is invalid</li>
<li>Misc is invalid</li>
<li>Preferences is invalid</li>
</ul>
</div>
</form>
Expand Down Expand Up @@ -1546,6 +1574,7 @@ Which outputs:
<ul class="rails-bootstrap-forms-error-summary">
<li>Email is invalid</li>
<li>Misc is invalid</li>
<li>Preferences is invalid</li>
</ul>
</form>
```
Expand Down
13 changes: 12 additions & 1 deletion demo/app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
// @import "actiontext";

label.required:after {
content:" *";
content: " *";
color: red;
}

.fragment {
@extend .border;
@extend .p-3;
}

form, .alert, .fragment {
> :last-child {
margin-bottom: 0 !important;
}
}
5 changes: 3 additions & 2 deletions demo/app/controllers/bootstrap_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def form
def fragment
@erb = params[:erb]

@erb.prepend '<div class="p-3 border">'
@erb.prepend '<div class="fragment">'
@erb << "</div>"
load_models
render inline: @erb, layout: "application" # rubocop: disable Rails/RenderInline
Expand All @@ -20,9 +20,10 @@ def load_models
@address_with_error.errors.add(:street)
@collection = [@address, @address_with_error]
@user = User.new email: "steve@example.com"
@user_with_error = User.new email: "steve.example.com", address: @address_with_error
@user_with_error = User.new email: "steve.example.com", address: @address_with_error, misc: 1, preferences: [1]
@user_with_error.errors.add(:email)
@user_with_error.errors.add(:misc)
@user_with_error.errors.add(:preferences)
@users = [@user]
end
end
6 changes: 1 addition & 5 deletions demo/app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
class User < ApplicationRecord
attr_accessor :remember_me

if Rails::VERSION::STRING >= "6.1"
serialize :preferences, coder: JSON
else
serialize :preferences, JSON
end
serialize :preferences, coder: JSON

validates :email, presence: true, length: { minimum: 5 }
validates :terms, acceptance: { accept: true }
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/04_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/05_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/06_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/07_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/08_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/09_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/10_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/11_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/12_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/13_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/14_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/15_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/16_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/20_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/21_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/23_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/24_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/25_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/26_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/27_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/28_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/29_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/30_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/36_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/39_example.png
Binary file modified demo/doc/screenshots/bootstrap/readme/40_example.png
Binary file modified demo/doc/screenshots/bootstrap/readme/41_example.png
Binary file modified demo/doc/screenshots/bootstrap/readme/42_example.png
Binary file modified demo/doc/screenshots/bootstrap/readme/45_example.png
Binary file modified demo/doc/screenshots/bootstrap/readme/46_example.png
Binary file modified demo/doc/screenshots/bootstrap/readme/47_example.png
Binary file modified demo/doc/screenshots/bootstrap/readme/48_example.png
Binary file modified demo/doc/screenshots/bootstrap/readme/49_example.png
Binary file modified demo/doc/screenshots/bootstrap/readme/53_example.png
2 changes: 1 addition & 1 deletion demo/test/system/bootstrap_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class BootstrapTest < ApplicationSystemTestCase
ERB

visit fragment_path erb: wrapped_erb
wrapper = find(".p-3")
wrapper = find(".fragment")
i = @screenshot_counter
screenshot :example, crop: bounds(wrapper)
wrapper = wrapper.find("form") if wrapped_erb != erb
Expand Down

0 comments on commit 61fc37a

Please sign in to comment.