rails_bootstrap_form 0.5.1 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +9 -1
- data/demo/app/views/users/_vertical_form.html.erb +4 -4
- data/gemfiles/common.gemfile +3 -0
- data/lib/rails_bootstrap_form/bootstrap_form_options.rb +26 -5
- data/lib/rails_bootstrap_form/components/check_box.rb +7 -0
- data/lib/rails_bootstrap_form/components/labels.rb +6 -3
- data/lib/rails_bootstrap_form/components/radio_button.rb +7 -0
- data/lib/rails_bootstrap_form/field_wrapper_builder.rb +14 -8
- data/lib/rails_bootstrap_form/input_group_builder.rb +4 -1
- data/lib/rails_bootstrap_form/inputs/base.rb +5 -1
- data/lib/rails_bootstrap_form/inputs.rb +3 -3
- data/lib/rails_bootstrap_form/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1031de2aa81bb74657e9a45f334c4dc4d67ee673e89874358881d8021388d8b9
|
4
|
+
data.tar.gz: 4a5d3c85afb71bd06005eb95c0b8abb76a429a46ea49f22b470943bba2a6f7ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 188081d3651b5f6977df21c3bfb4436e44b3d96685ef8b6fc36b7805056b205ab77ced5f3ad4d3094217116e47f04e8a07a914db1f073c60be664bd4acf33694
|
7
|
+
data.tar.gz: 180295d5dbc0159f5181183be148203565d877d874d978074af43dd31ba0cfb7e7d8d2be3bcf3d3c72e1abe6d4ff58636da8c4386be3b09d64380edc4ef06b2d
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rails_bootstrap_form (0.5.
|
4
|
+
rails_bootstrap_form (0.5.3)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: http://rubygems.org/
|
@@ -83,6 +83,7 @@ GEM
|
|
83
83
|
crass (1.0.6)
|
84
84
|
date (3.3.3)
|
85
85
|
diff-lcs (1.5.0)
|
86
|
+
docile (1.4.0)
|
86
87
|
erubi (1.12.0)
|
87
88
|
execjs (2.8.1)
|
88
89
|
ffi (1.15.5)
|
@@ -176,6 +177,12 @@ GEM
|
|
176
177
|
sprockets (> 3.0)
|
177
178
|
sprockets-rails
|
178
179
|
tilt
|
180
|
+
simplecov (0.22.0)
|
181
|
+
docile (~> 1.1)
|
182
|
+
simplecov-html (~> 0.11)
|
183
|
+
simplecov_json_formatter (~> 0.1)
|
184
|
+
simplecov-html (0.12.3)
|
185
|
+
simplecov_json_formatter (0.1.4)
|
179
186
|
sprockets (4.2.0)
|
180
187
|
concurrent-ruby (~> 1.0)
|
181
188
|
rack (>= 2.2.4, < 4)
|
@@ -207,6 +214,7 @@ DEPENDENCIES
|
|
207
214
|
rake (~> 13.0)
|
208
215
|
rspec-rails
|
209
216
|
sassc-rails
|
217
|
+
simplecov
|
210
218
|
sprockets-rails
|
211
219
|
sqlite3 (~> 1.4)
|
212
220
|
|
@@ -4,7 +4,7 @@
|
|
4
4
|
</div>
|
5
5
|
<div class="card-body">
|
6
6
|
<%= bootstrap_form_for @user, bootstrap_form: {} do |form| %>
|
7
|
-
<%= form.text_field :name, autocomplete: "new-name", bootstrap_form: {} %>
|
7
|
+
<%= form.text_field :name, autocomplete: "new-name", class: "dsds", bootstrap_form: {} %>
|
8
8
|
<%= form.text_field :email, autocomplete: "new-email", bootstrap_form: {} %>
|
9
9
|
<%= form.text_field :password, autocomplete: "new-password" %>
|
10
10
|
<%= form.phone_field :mobile_number %>
|
@@ -12,13 +12,13 @@
|
|
12
12
|
<%= form.check_box :terms, bootstrap_form: {switch: false}, required: true %>
|
13
13
|
<%= form.range_field :excellence %>
|
14
14
|
<%= form.url_field :blog_url %>
|
15
|
-
<%= form.collection_radio_buttons :fruit_id, ::Fruit.all, :id, :name, {bootstrap_form: {
|
15
|
+
<%= form.collection_radio_buttons :fruit_id, ::Fruit.all, :id, :name, {bootstrap_form: {inline: true}, checked: form.object.fruit_id} %>
|
16
16
|
<%= form.color_field :favorite_color %>
|
17
|
-
<%= form.collection_check_boxes :skill_ids, ::Skill.all, :id, :name, {bootstrap_form: {
|
17
|
+
<%= form.collection_check_boxes :skill_ids, ::Skill.all, :id, :name, {bootstrap_form: {inline: true}} %>
|
18
18
|
<%= form.fields_for :address, include_id: false do |address_form| %>
|
19
19
|
<%= address_form.text_area :street %>
|
20
20
|
<%= address_form.text_field :state %>
|
21
|
-
<%= address_form.grouped_collection_select :city, ::Country.
|
21
|
+
<%= address_form.grouped_collection_select :city, ::Country.includes(:cities), :cities, :name, :id, :name, {include_blank: "Select city"} %>
|
22
22
|
<%= address_form.text_field :postal_code %>
|
23
23
|
<%= address_form.select :country_id, options_for_select(::Country.pluck(:name, :id), address_form.object.country_id),
|
24
24
|
{include_blank: "Select Country", bootstrap_form: {}} %>
|
data/gemfiles/common.gemfile
CHANGED
@@ -90,25 +90,40 @@ module RailsBootstrapForm
|
|
90
90
|
# Default is `false`.
|
91
91
|
attr_accessor :switch
|
92
92
|
|
93
|
+
# Controls the HTML attributes and options that will be added to the field wrapper.
|
94
|
+
# Default is `{}`.
|
95
|
+
attr_accessor :wrapper_options
|
96
|
+
|
97
|
+
# Option to specify the size of input groups and fields.
|
98
|
+
# The valid values are `sm` and `lg`. The default value is `nil`.
|
99
|
+
attr_accessor :size
|
100
|
+
|
101
|
+
# Option to render checkboxes and radio buttons inline.
|
102
|
+
# The default value if `false`.
|
103
|
+
#
|
104
|
+
# Example:
|
105
|
+
# form.collection_radio_buttons :choices, ["yes", "no"], :to_s, :to_s, bootstrap_form: {inline: true}
|
106
|
+
attr_accessor :inline
|
107
|
+
|
93
108
|
def initialize(options = {})
|
94
109
|
set_defaults
|
95
110
|
set_bootstrap_form_options(options)
|
96
111
|
end
|
97
112
|
|
98
|
-
def
|
113
|
+
def layout_horizontal?
|
99
114
|
@layout.to_s == "horizontal"
|
100
115
|
end
|
101
116
|
|
102
|
-
def
|
117
|
+
def layout_inline?
|
103
118
|
@layout.to_s == "inline"
|
104
119
|
end
|
105
120
|
|
106
|
-
def
|
121
|
+
def layout_vertical?
|
107
122
|
@layout.to_s == "vertical"
|
108
123
|
end
|
109
124
|
|
110
|
-
def
|
111
|
-
|
125
|
+
def inline?
|
126
|
+
self.inline
|
112
127
|
end
|
113
128
|
|
114
129
|
# This will return a copy of `BootstrapFormOptions` object with new options set
|
@@ -152,6 +167,12 @@ module RailsBootstrapForm
|
|
152
167
|
@static_field_class = "form-control-plaintext"
|
153
168
|
|
154
169
|
@switch = false
|
170
|
+
|
171
|
+
@wrapper_options = {}
|
172
|
+
|
173
|
+
@size = nil
|
174
|
+
|
175
|
+
@inline = false
|
155
176
|
end
|
156
177
|
|
157
178
|
private :set_defaults
|
@@ -27,6 +27,12 @@ module RailsBootstrapForm
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
+
def check_box_wrapper_options(bootstrap_options)
|
31
|
+
{}.tap do |option|
|
32
|
+
option[:class] = check_box_wrapper_class(bootstrap_options)
|
33
|
+
end.merge(bootstrap_options.wrapper_options)
|
34
|
+
end
|
35
|
+
|
30
36
|
def check_box_label_text(attribute, options, bootstrap_options, &block)
|
31
37
|
block ? capture(&block) : label_text(attribute, bootstrap_options)
|
32
38
|
end
|
@@ -56,6 +62,7 @@ module RailsBootstrapForm
|
|
56
62
|
classes = Array("form-check")
|
57
63
|
classes << "form-switch" if bootstrap_options.switch
|
58
64
|
classes << "form-check-inline" if bootstrap_options.inline?
|
65
|
+
classes << "mb-3"
|
59
66
|
classes.flatten.compact
|
60
67
|
end
|
61
68
|
|
@@ -8,12 +8,15 @@ module RailsBootstrapForm
|
|
8
8
|
extend ActiveSupport::Concern
|
9
9
|
|
10
10
|
def self.included(base_class)
|
11
|
-
def draw_label(attribute, bootstrap_options)
|
11
|
+
def draw_label(attribute, options, bootstrap_options)
|
12
12
|
unless bootstrap_options.skip_label
|
13
|
-
|
13
|
+
label_options = {
|
14
|
+
class: label_classes(attribute, bootstrap_options)
|
15
|
+
}
|
16
|
+
label_options[:for] = options[:id] if options[:id].present?
|
14
17
|
label_text = label_text(attribute, bootstrap_options)
|
15
18
|
|
16
|
-
label(attribute, label_text,
|
19
|
+
label(attribute, label_text, label_options)
|
17
20
|
end
|
18
21
|
end
|
19
22
|
|
@@ -28,6 +28,12 @@ module RailsBootstrapForm
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
+
def radio_button_wrapper_options(bootstrap_options)
|
32
|
+
{}.tap do |option|
|
33
|
+
option[:class] = radio_button_wrapper_class(bootstrap_options)
|
34
|
+
end.merge(bootstrap_options.wrapper_options)
|
35
|
+
end
|
36
|
+
|
31
37
|
def radio_button_value(attribute, value)
|
32
38
|
# label's `for` attribute needs to match checkbox tag's id,
|
33
39
|
# IE sanitized value, IE
|
@@ -52,6 +58,7 @@ module RailsBootstrapForm
|
|
52
58
|
def radio_button_wrapper_class(bootstrap_options)
|
53
59
|
classes = Array("form-check")
|
54
60
|
classes << "form-check-inline" if bootstrap_options.inline?
|
61
|
+
classes << "mb-3"
|
55
62
|
classes.flatten.compact
|
56
63
|
end
|
57
64
|
|
@@ -13,11 +13,11 @@ module RailsBootstrapForm
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def field_wrapper(attribute, bootstrap_options, options, &block)
|
16
|
-
label = draw_label(attribute, bootstrap_options)
|
16
|
+
label = draw_label(attribute, options, bootstrap_options)
|
17
17
|
help_text = help_text(attribute, bootstrap_options)
|
18
18
|
|
19
19
|
if bootstrap_options.floating
|
20
|
-
tag.div(
|
20
|
+
tag.div(**field_wrapper_options(bootstrap_options)) do
|
21
21
|
concat(input_group_wrapper(attribute, bootstrap_options) do
|
22
22
|
tag.div(class: floating_label_classes(attribute)) do
|
23
23
|
concat(capture(&block))
|
@@ -27,7 +27,7 @@ module RailsBootstrapForm
|
|
27
27
|
concat(help_text)
|
28
28
|
end
|
29
29
|
else
|
30
|
-
tag.div(
|
30
|
+
tag.div(**field_wrapper_options(bootstrap_options)) do
|
31
31
|
concat(label)
|
32
32
|
concat(input_group_wrapper(attribute, bootstrap_options) do
|
33
33
|
capture(&block)
|
@@ -37,14 +37,17 @@ module RailsBootstrapForm
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
+
def field_wrapper_options(bootstrap_options)
|
41
|
+
{}.tap do |option|
|
42
|
+
option[:class] = field_wrapper_classes
|
43
|
+
end.merge(bootstrap_options.wrapper_options)
|
44
|
+
end
|
45
|
+
|
40
46
|
def field_wrapper_classes
|
41
47
|
classes = [form_wrapper_default_class]
|
42
48
|
classes.flatten.compact
|
43
49
|
end
|
44
50
|
|
45
|
-
def field_wrapper_options
|
46
|
-
end
|
47
|
-
|
48
51
|
def form_wrapper_default_class
|
49
52
|
"mb-3"
|
50
53
|
end
|
@@ -52,14 +55,17 @@ module RailsBootstrapForm
|
|
52
55
|
def field_css_options(attribute, bootstrap_options, options, html_options)
|
53
56
|
css_options = (html_options || options)
|
54
57
|
|
55
|
-
field_classes = [
|
58
|
+
field_classes = Array(options[:class])
|
59
|
+
field_classes << [
|
56
60
|
bootstrap_options.field_class,
|
57
61
|
bootstrap_options.additional_field_class
|
58
62
|
]
|
59
63
|
field_classes << "is-invalid" if is_invalid?(attribute)
|
64
|
+
if is_size_valid?(bootstrap_options)
|
65
|
+
field_classes << "#{bootstrap_options.field_class}-#{bootstrap_options.size}"
|
66
|
+
end
|
60
67
|
|
61
68
|
css_options[:class] = field_classes.flatten.compact
|
62
|
-
|
63
69
|
css_options.merge!(required_field_options(attribute, options))
|
64
70
|
|
65
71
|
if bootstrap_options.floating
|
@@ -26,7 +26,10 @@ module RailsBootstrapForm
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def input_group_classes(attribute, bootstrap_options)
|
29
|
-
classes =
|
29
|
+
classes = Array("input-group") << bootstrap_options.additional_input_group_class
|
30
|
+
if is_size_valid?(bootstrap_options)
|
31
|
+
classes << "input-group-#{bootstrap_options.size}"
|
32
|
+
end
|
30
33
|
# Require `has-validation` class if field has errors.
|
31
34
|
classes << "has-validation" if is_invalid?(attribute)
|
32
35
|
classes.flatten.compact
|
@@ -17,7 +17,11 @@ module RailsBootstrapForm
|
|
17
17
|
"rails-bootstrap-forms-#{field_tag_name.to_s.tr("_", "-")}"
|
18
18
|
end
|
19
19
|
|
20
|
-
|
20
|
+
def is_size_valid?(bootstrap_options)
|
21
|
+
bootstrap_options.size && %i(sm lg).include?(bootstrap_options.size)
|
22
|
+
end
|
23
|
+
|
24
|
+
private :collection_input_checked?, :control_specific_class, :is_size_valid?
|
21
25
|
end
|
22
26
|
end
|
23
27
|
end
|
@@ -45,7 +45,7 @@ module RailsBootstrapForm
|
|
45
45
|
end
|
46
46
|
|
47
47
|
DATE_SELECT_HELPERS.each do |field_tag_name|
|
48
|
-
define_method(field_tag_name) do |attribute, options = {}, html_options = {}
|
48
|
+
define_method(field_tag_name) do |attribute, options = {}, html_options = {}|
|
49
49
|
options = {bootstrap_form: {field_class: "form-select"}}.deep_merge!(options)
|
50
50
|
|
51
51
|
field_wrapper_builder(attribute, options, html_options) do
|
@@ -137,7 +137,7 @@ module RailsBootstrapForm
|
|
137
137
|
|
138
138
|
check_box_label = check_box_label(attribute, checked_value, options, bootstrap_options, &block)
|
139
139
|
|
140
|
-
check_box_html = tag.div(
|
140
|
+
check_box_html = tag.div(**check_box_wrapper_options(bootstrap_options)) do
|
141
141
|
concat(check_box_field)
|
142
142
|
concat(check_box_label)
|
143
143
|
concat(check_box_help_text) unless bootstrap_options.inline?
|
@@ -157,7 +157,7 @@ module RailsBootstrapForm
|
|
157
157
|
|
158
158
|
radio_button_label = radio_button_label(attribute, value, options, bootstrap_options)
|
159
159
|
|
160
|
-
radio_button_html = tag.div(
|
160
|
+
radio_button_html = tag.div(**radio_button_wrapper_options(bootstrap_options)) do
|
161
161
|
concat(radio_button_field)
|
162
162
|
concat(radio_button_label)
|
163
163
|
concat(radio_button_help_text) unless bootstrap_options.inline?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_bootstrap_form
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Harshal LADHE (shivam091)
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-05-
|
11
|
+
date: 2023-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: generator_spec
|