rails_bootstrap_form 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +9 -1
- data/demo/app/views/users/_vertical_form.html.erb +1 -1
- data/gemfiles/common.gemfile +3 -0
- data/lib/rails_bootstrap_form/bootstrap_form_options.rb +12 -4
- data/lib/rails_bootstrap_form/components/check_box.rb +7 -1
- data/lib/rails_bootstrap_form/components/labels.rb +6 -3
- data/lib/rails_bootstrap_form/components/radio_button.rb +7 -1
- 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: ed3da45cc2109afbc15026f1a12f80000890c7b7759bc7dbbbe855f3184bf0a2
|
4
|
+
data.tar.gz: 5e7897c4c60eb47a89f2eaf26a3f3ad46b5cc78cdc5519ff1dfe755302e7ab40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b84a087632ef6236a0b1975910ae6cabe61f5f1f70aa0f2950c765f53c23caa93de366b00517622a5fffabff0fb34794a563d04eb7ebe8bf4061bec6858ef57
|
7
|
+
data.tar.gz: 288e303d2c86355e5cd4a88d9046a84704d9091954981d7dee818f3f57f583995fa8bde1f28aa7f067ff851724deb6c8e00c03912a6c240da266000d353bd385
|
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.2)
|
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 %>
|
data/gemfiles/common.gemfile
CHANGED
@@ -90,6 +90,14 @@ 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
|
+
|
93
101
|
def initialize(options = {})
|
94
102
|
set_defaults
|
95
103
|
set_bootstrap_form_options(options)
|
@@ -107,10 +115,6 @@ module RailsBootstrapForm
|
|
107
115
|
@layout.to_s == "vertical"
|
108
116
|
end
|
109
117
|
|
110
|
-
def floating?
|
111
|
-
@layout.to_s == "floating"
|
112
|
-
end
|
113
|
-
|
114
118
|
# This will return a copy of `BootstrapFormOptions` object with new options set
|
115
119
|
# that don't affect original object. This way we can have options specific
|
116
120
|
# to a given form field. For example, we can change grid just for one field:
|
@@ -152,6 +156,10 @@ module RailsBootstrapForm
|
|
152
156
|
@static_field_class = "form-control-plaintext"
|
153
157
|
|
154
158
|
@switch = false
|
159
|
+
|
160
|
+
@wrapper_options = {}
|
161
|
+
|
162
|
+
@size = nil
|
155
163
|
end
|
156
164
|
|
157
165
|
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
|
@@ -55,7 +61,7 @@ module RailsBootstrapForm
|
|
55
61
|
def check_box_wrapper_class(bootstrap_options)
|
56
62
|
classes = Array("form-check")
|
57
63
|
classes << "form-switch" if bootstrap_options.switch
|
58
|
-
classes << "form-check-inline"
|
64
|
+
classes << (bootstrap_options.inline? ? "form-check-inline" : "mb-3")
|
59
65
|
classes.flatten.compact
|
60
66
|
end
|
61
67
|
|
@@ -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
|
@@ -51,7 +57,7 @@ module RailsBootstrapForm
|
|
51
57
|
|
52
58
|
def radio_button_wrapper_class(bootstrap_options)
|
53
59
|
classes = Array("form-check")
|
54
|
-
classes << "form-check-inline"
|
60
|
+
classes << (bootstrap_options.inline? ? "form-check-inline" : "mb-3")
|
55
61
|
classes.flatten.compact
|
56
62
|
end
|
57
63
|
|
@@ -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.2
|
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
|