rails_bootstrap_form 0.6.2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/Gemfile.lock +1 -1
- data/demo/app/views/users/_horizontal_form.html.erb +1 -1
- data/demo/app/views/users/_vertical_form.html.erb +1 -1
- data/lib/rails_bootstrap_form/bootstrap_form_options.rb +11 -4
- data/lib/rails_bootstrap_form/field_wrapper_builder.rb +2 -2
- data/lib/rails_bootstrap_form/helpers/buttons.rb +39 -0
- data/lib/rails_bootstrap_form/helpers/check_box.rb +3 -3
- data/lib/rails_bootstrap_form/helpers/labels.rb +2 -2
- data/lib/rails_bootstrap_form/helpers/radio_button.rb +2 -2
- data/lib/rails_bootstrap_form/helpers.rb +15 -1
- data/lib/rails_bootstrap_form/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad6e14683d4d77bee3ee35855f75a8af8258bf8208f47504678e2a9d9b3be743
|
4
|
+
data.tar.gz: f0a40a462746c5990a5df46ef604fce57a43359cda481b42557ee5e182e65019
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4db5095b17363d92f5fe629d05a8cc1031e925aeecc461a113a905dd98e3b6b6bff3298c3154332b82160a3adfd72e358cef2578bc7ecb0af24296d0bdd9102
|
7
|
+
data.tar.gz: 603478636468cc3a2d379b6499a15674b21d990aed61b333b2aa3db356b96af703dc423b67c2fb1b0a4a74a1589c02bd11e0c11c91229d526a65c330e6bbda41
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,17 @@ You can find recent releases with docs in GitHub:
|
|
4
4
|
|
5
5
|
https://github.com/shivam091/rails_bootstrap_form/releases
|
6
6
|
|
7
|
+
## [0.7.0](https://github.com/shivam091/rails_bootstrap_form/compare/v0.6.2...v0.7.0) - 2023-05-24
|
8
|
+
|
9
|
+
### What's new
|
10
|
+
- Added helper methods for rendering submit buttons on forms.
|
11
|
+
|
12
|
+
## [0.6.2](https://github.com/shivam091/rails_bootstrap_form/compare/v0.6.1...v0.6.2) - 2023-05-24
|
13
|
+
|
14
|
+
### What's fixed
|
15
|
+
- Added support for setting bootstrap options of parent form to `fields_for` ([#10](https://github.com/shivam091/rails_bootstrap_form/issues/10))
|
16
|
+
- Ignore skip_label option when field has floating labels ([#9](https://github.com/shivam091/rails_bootstrap_form/issues/9))
|
17
|
+
|
7
18
|
## [0.6.1](https://github.com/shivam091/rails_bootstrap_form/compare/v0.6.0...v0.6.1) - 2023-05-24
|
8
19
|
|
9
20
|
### What's changed
|
data/Gemfile.lock
CHANGED
@@ -24,7 +24,7 @@
|
|
24
24
|
<% end %>
|
25
25
|
<%= form.check_box :terms, required: true %>
|
26
26
|
<div class="mt-3">
|
27
|
-
<%= form.
|
27
|
+
<%= form.primary "Register" %>
|
28
28
|
<%= link_to "Cancel", users_path, class: "btn btn-secondary" %>
|
29
29
|
</div>
|
30
30
|
<% end %>
|
@@ -24,7 +24,7 @@
|
|
24
24
|
<% end %>
|
25
25
|
<%= form.check_box :terms, required: true %>
|
26
26
|
<div class="mt-3">
|
27
|
-
<%= form.
|
27
|
+
<%= form.primary "Register" %>
|
28
28
|
<%= link_to "Cancel", users_path, class: "btn btn-secondary" %>
|
29
29
|
</div>
|
30
30
|
<% end %>
|
@@ -119,6 +119,11 @@ module RailsBootstrapForm
|
|
119
119
|
# The default value is `col-sm-10`.
|
120
120
|
attr_accessor :field_col_wrapper_class
|
121
121
|
|
122
|
+
# Option to render submit button using `<button type="submit">` instead of
|
123
|
+
# `<input type="submit">`.
|
124
|
+
# The default value is `false`.
|
125
|
+
attr_accessor :render_as_button
|
126
|
+
|
122
127
|
def initialize(options = {})
|
123
128
|
set_defaults
|
124
129
|
set_bootstrap_form_options(options)
|
@@ -136,10 +141,6 @@ module RailsBootstrapForm
|
|
136
141
|
@layout.to_s == "vertical"
|
137
142
|
end
|
138
143
|
|
139
|
-
def inline?
|
140
|
-
self.inline
|
141
|
-
end
|
142
|
-
|
143
144
|
# This will return a copy of `BootstrapFormOptions` object with new options set
|
144
145
|
# that don't affect original object. This way we can have options specific
|
145
146
|
# to a given form field. For example, we can change grid just for one field:
|
@@ -161,6 +162,10 @@ module RailsBootstrapForm
|
|
161
162
|
end
|
162
163
|
end
|
163
164
|
|
165
|
+
%i(inline floating switch skip_label hide_label render_as_button).each do |method|
|
166
|
+
define_method("#{method}?") { self.send(method) }
|
167
|
+
end
|
168
|
+
|
164
169
|
def set_defaults
|
165
170
|
@layout = "vertical"
|
166
171
|
|
@@ -191,6 +196,8 @@ module RailsBootstrapForm
|
|
191
196
|
@label_col_class = "col-form-label"
|
192
197
|
@label_col_wrapper_class = "col-sm-2"
|
193
198
|
@field_col_wrapper_class = "col-sm-10"
|
199
|
+
|
200
|
+
@render_as_button = false
|
194
201
|
end
|
195
202
|
|
196
203
|
private :set_defaults
|
@@ -27,7 +27,7 @@ module RailsBootstrapForm
|
|
27
27
|
end)
|
28
28
|
end
|
29
29
|
else
|
30
|
-
if bootstrap_options.floating
|
30
|
+
if bootstrap_options.floating?
|
31
31
|
tag.div(**field_wrapper_options(bootstrap_options)) do
|
32
32
|
concat(input_group_wrapper(attribute, bootstrap_options) do
|
33
33
|
tag.div(class: floating_label_classes(attribute)) do
|
@@ -82,7 +82,7 @@ module RailsBootstrapForm
|
|
82
82
|
css_options[:class] = field_classes.flatten.compact
|
83
83
|
css_options.merge!(required_field_options(attribute, options))
|
84
84
|
|
85
|
-
if (bootstrap_options.floating && !bootstrap_options.layout_horizontal?)
|
85
|
+
if (bootstrap_options.floating? && !bootstrap_options.layout_horizontal?)
|
86
86
|
css_options[:placeholder] ||= label_text(attribute, bootstrap_options)
|
87
87
|
end
|
88
88
|
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# -*- frozen_string_literal: true -*-
|
3
|
+
# -*- warn_indent: true -*-
|
4
|
+
|
5
|
+
module RailsBootstrapForm
|
6
|
+
module Helpers
|
7
|
+
module Buttons
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
def self.included(base_class)
|
11
|
+
def render_button(value = nil, options = {}, &block)
|
12
|
+
value, options = nil, value if value.is_a?(Hash)
|
13
|
+
bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap_form))
|
14
|
+
|
15
|
+
if (bootstrap_options.render_as_button? || block)
|
16
|
+
button(value, options, &block)
|
17
|
+
else
|
18
|
+
submit(value, options)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def secondary(value = nil, options = {}, &block)
|
23
|
+
add_css_class!(options, "btn btn-secondary")
|
24
|
+
render_button(value, options, &block)
|
25
|
+
end
|
26
|
+
|
27
|
+
def primary(value = nil, options = {}, &block)
|
28
|
+
add_css_class!(options, "btn btn-primary")
|
29
|
+
render_button(value, options, &block)
|
30
|
+
end
|
31
|
+
|
32
|
+
def danger(value = nil, options = {}, &block)
|
33
|
+
add_css_class!(options, "btn btn-danger")
|
34
|
+
render_button(value, options, &block)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -9,7 +9,7 @@ module RailsBootstrapForm
|
|
9
9
|
|
10
10
|
def self.included(base_class)
|
11
11
|
def check_box_label(attribute, checked_value, options, bootstrap_options, &block)
|
12
|
-
unless bootstrap_options.skip_label
|
12
|
+
unless bootstrap_options.skip_label?
|
13
13
|
label_options = {
|
14
14
|
class: check_box_label_class(attribute, bootstrap_options, options)
|
15
15
|
}
|
@@ -54,13 +54,13 @@ module RailsBootstrapForm
|
|
54
54
|
classes = Array("form-check-label") << bootstrap_options.additional_label_class
|
55
55
|
classes << "required" if is_field_required?(attribute, options) && !bootstrap_options.inline?
|
56
56
|
classes << "is-invalid" if is_invalid?(attribute)
|
57
|
-
classes << bootstrap_options.hide_class if bootstrap_options.hide_label
|
57
|
+
classes << bootstrap_options.hide_class if bootstrap_options.hide_label?
|
58
58
|
classes.flatten.compact
|
59
59
|
end
|
60
60
|
|
61
61
|
def check_box_wrapper_class(bootstrap_options)
|
62
62
|
classes = Array("form-check")
|
63
|
-
classes << "form-switch" if bootstrap_options.switch
|
63
|
+
classes << "form-switch" if bootstrap_options.switch?
|
64
64
|
classes << "form-check-inline" if bootstrap_options.inline?
|
65
65
|
classes << "mb-3" unless (bootstrap_options.layout_horizontal? || bootstrap_options.inline?)
|
66
66
|
classes.flatten.compact
|
@@ -9,7 +9,7 @@ module RailsBootstrapForm
|
|
9
9
|
|
10
10
|
def self.included(base_class)
|
11
11
|
def draw_label(attribute, options, bootstrap_options)
|
12
|
-
unless bootstrap_options.skip_label && !bootstrap_options.floating
|
12
|
+
unless bootstrap_options.skip_label? && !bootstrap_options.floating?
|
13
13
|
label_options = {
|
14
14
|
class: label_classes(attribute, bootstrap_options)
|
15
15
|
}
|
@@ -28,7 +28,7 @@ module RailsBootstrapForm
|
|
28
28
|
bootstrap_options.label_class
|
29
29
|
end
|
30
30
|
classes << bootstrap_options.additional_label_class
|
31
|
-
classes << bootstrap_options.hide_class if bootstrap_options.hide_label
|
31
|
+
classes << bootstrap_options.hide_class if bootstrap_options.hide_label?
|
32
32
|
classes << "required" if is_attribute_required?(attribute)
|
33
33
|
classes << "is-invalid" if is_invalid?(attribute)
|
34
34
|
classes.flatten.compact
|
@@ -9,7 +9,7 @@ module RailsBootstrapForm
|
|
9
9
|
|
10
10
|
def self.included(base_class)
|
11
11
|
def radio_button_label(attribute, value, options, bootstrap_options)
|
12
|
-
unless bootstrap_options.skip_label
|
12
|
+
unless bootstrap_options.skip_label?
|
13
13
|
label_options = {
|
14
14
|
value: value,
|
15
15
|
class: radio_button_label_class(attribute, bootstrap_options, options)
|
@@ -51,7 +51,7 @@ module RailsBootstrapForm
|
|
51
51
|
classes = Array("form-check-label") << bootstrap_options.additional_label_class
|
52
52
|
classes << "required" if is_field_required?(attribute, options) && !bootstrap_options.inline?
|
53
53
|
classes << "is-invalid" if is_invalid?(attribute)
|
54
|
-
classes << bootstrap_options.hide_class if bootstrap_options.hide_label
|
54
|
+
classes << bootstrap_options.hide_class if bootstrap_options.hide_label?
|
55
55
|
classes.flatten.compact
|
56
56
|
end
|
57
57
|
|
@@ -13,6 +13,7 @@ module RailsBootstrapForm
|
|
13
13
|
autoload :Errors
|
14
14
|
autoload :CheckBox
|
15
15
|
autoload :RadioButton
|
16
|
+
autoload :Buttons
|
16
17
|
|
17
18
|
include HelpText
|
18
19
|
include Labels
|
@@ -20,6 +21,7 @@ module RailsBootstrapForm
|
|
20
21
|
include Errors
|
21
22
|
include CheckBox
|
22
23
|
include RadioButton
|
24
|
+
include Buttons
|
23
25
|
|
24
26
|
def self.included(base_class)
|
25
27
|
def collection_input_checked?(checked, obj, input_value)
|
@@ -39,7 +41,19 @@ module RailsBootstrapForm
|
|
39
41
|
label_col_wrapper_class.gsub(/\bcol-(\w+)-(\d)\b/, 'offset-\1-\2')
|
40
42
|
end
|
41
43
|
|
42
|
-
|
44
|
+
def add_css_class!(options, css_class)
|
45
|
+
the_class = [options[:class], css_class].compact
|
46
|
+
options[:class] = the_class if the_class.present?
|
47
|
+
end
|
48
|
+
|
49
|
+
def remove_css_class!(options, css_class)
|
50
|
+
the_class = options[:class].to_s.split(" ")
|
51
|
+
options[:class] = (the_class - [css_class]).compact.join(" ")
|
52
|
+
options.delete(:class) if options[:class].blank?
|
53
|
+
end
|
54
|
+
|
55
|
+
private :collection_input_checked?, :control_specific_class, :is_size_valid?,
|
56
|
+
:add_css_class!, :remove_css_class!
|
43
57
|
end
|
44
58
|
end
|
45
59
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_bootstrap_form
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Harshal LADHE (shivam091)
|
@@ -143,6 +143,7 @@ files:
|
|
143
143
|
- lib/rails_bootstrap_form/engine.rb
|
144
144
|
- lib/rails_bootstrap_form/field_wrapper_builder.rb
|
145
145
|
- lib/rails_bootstrap_form/helpers.rb
|
146
|
+
- lib/rails_bootstrap_form/helpers/buttons.rb
|
146
147
|
- lib/rails_bootstrap_form/helpers/check_box.rb
|
147
148
|
- lib/rails_bootstrap_form/helpers/errors.rb
|
148
149
|
- lib/rails_bootstrap_form/helpers/help_text.rb
|