rails_bootstrap_form 0.5.0 → 0.5.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d6b50f9d02bd4dce2b18bcbf5ce63159d4b62ef9c9b28a4e6e696b9780721e5f
4
- data.tar.gz: fdd32e9dff7e170d3a220f7ba06fb981e5fe1c24f7a292aa9f20133d624fc27f
3
+ metadata.gz: 75f1c7df21987622c3341031991186ceff26dc21f48c301ee2017fb47dd1074a
4
+ data.tar.gz: e84fbf45f5bcff4bfad1904253c5e549fa616ebc9d646b762facb78cca121ce7
5
5
  SHA512:
6
- metadata.gz: e769de6bd7e33924dda68e244acc498b8586ff7eb23242abe228c959335290f1869142dbff651166c958e5f7aa863961b69e0c85ee35ce3b2c7fef94c76e573c
7
- data.tar.gz: 9e2dc6b8c51126c2b05760752c656ce6098c4ac178e66c9d7fc44f2e9a0013391dd82b3c36efb07562a6473adfff1af318905e3eb3a392bd6cce2db2dc83431d
6
+ metadata.gz: ee6cf0a877cff1e96ccc3e95495c331f41c5af536a23332b58669a10f6c6db6c3f1dc9f5fd3cd2fc2e51c0040380e18a7477231f4b108d306593dfc1f6844fa7
7
+ data.tar.gz: 39f8e46ae208727fd81127cb3c8de3f32878c16b957ff21fc882f6a250e7972bd00f573dd4dd6a958140d7564e57a4e70e1a86eb30c484e73b3ab42ece3a2bb5
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails_bootstrap_form (0.5.0)
4
+ rails_bootstrap_form (0.5.1)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -18,7 +18,7 @@
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.all, :cities, :name, :id, :name %>
21
+ <%= address_form.grouped_collection_select :city, ::Country.all, :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: {}} %>
@@ -43,7 +43,9 @@
43
43
  help_texts: {
44
44
  user: {
45
45
  email: "Please use official email address",
46
- terms: "You must first accept terms and conditions in order to continue"
46
+ terms: "You must first accept terms and conditions in order to continue",
47
+ skill_ids: "Select your strong skills",
48
+ fruit_id: "Select your favorite fruit"
47
49
  }
48
50
  },
49
51
  }
@@ -25,10 +25,6 @@ module RailsBootstrapForm
25
25
  options[:html].reverse_merge!(RailsBootstrapForm.config.default_form_attributes)
26
26
  end
27
27
 
28
- def control_specific_class(field_tag_name)
29
- "rails-bootstrap-forms-#{field_tag_name.to_s.tr("_", "-")}"
30
- end
31
-
32
- private :apply_default_form_options, :control_specific_class
28
+ private :apply_default_form_options
33
29
  end
34
30
  end
@@ -46,14 +46,14 @@ module RailsBootstrapForm
46
46
 
47
47
  def check_box_label_class(attribute, bootstrap_options, options)
48
48
  classes = Array("form-check-label") << bootstrap_options.additional_label_class
49
- classes << "required" if is_field_required?(attribute, options)
49
+ classes << "required" if is_field_required?(attribute, options) && !bootstrap_options.inline?
50
50
  classes << "is-invalid" if is_invalid?(attribute)
51
51
  classes << bootstrap_options.hide_class if bootstrap_options.hide_label
52
52
  classes.flatten.compact
53
53
  end
54
54
 
55
55
  def check_box_wrapper_class(bootstrap_options)
56
- classes = ["mb-3", "form-check"]
56
+ classes = Array("form-check")
57
57
  classes << "form-switch" if bootstrap_options.switch
58
58
  classes << "form-check-inline" if bootstrap_options.inline?
59
59
  classes.flatten.compact
@@ -43,14 +43,14 @@ module RailsBootstrapForm
43
43
 
44
44
  def radio_button_label_class(attribute, bootstrap_options, options)
45
45
  classes = Array("form-check-label") << bootstrap_options.additional_label_class
46
- classes << "required" if is_field_required?(attribute, options)
46
+ classes << "required" if is_field_required?(attribute, options) && !bootstrap_options.inline?
47
47
  classes << "is-invalid" if is_invalid?(attribute)
48
48
  classes << bootstrap_options.hide_class if bootstrap_options.hide_label
49
49
  classes.flatten.compact
50
50
  end
51
51
 
52
52
  def radio_button_wrapper_class(bootstrap_options)
53
- classes = ["mb-3", "form-check"]
53
+ classes = Array("form-check")
54
54
  classes << "form-check-inline" if bootstrap_options.inline?
55
55
  classes.flatten.compact
56
56
  end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # -*- frozen_string_literal: true -*-
3
+ # -*- warn_indent: true -*-
4
+
5
+ module RailsBootstrapForm
6
+ module Inputs
7
+ module Base
8
+ extend ActiveSupport::Concern
9
+
10
+ def self.included(base_class)
11
+ def collection_input_checked?(checked, obj, input_value)
12
+ checked == input_value || Array(checked).try(:include?, input_value) ||
13
+ checked == obj || Array(checked).try(:include?, obj)
14
+ end
15
+
16
+ def control_specific_class(field_tag_name)
17
+ "rails-bootstrap-forms-#{field_tag_name.to_s.tr("_", "-")}"
18
+ end
19
+
20
+ private :collection_input_checked?, :control_specific_class
21
+ end
22
+ end
23
+ end
24
+ end
@@ -5,6 +5,12 @@
5
5
  module RailsBootstrapForm
6
6
  module Inputs
7
7
 
8
+ extend ActiveSupport::Autoload
9
+
10
+ autoload :Base
11
+
12
+ include Base
13
+
8
14
  FIELD_HELPERS = %i[
9
15
  text_field
10
16
  url_field
@@ -134,8 +140,8 @@ module RailsBootstrapForm
134
140
  check_box_html = tag.div(class: check_box_wrapper_class(bootstrap_options)) do
135
141
  concat(check_box_field)
136
142
  concat(check_box_label)
137
- concat(check_box_help_text)
138
- concat(generate_error(attribute)) if is_invalid?(attribute)
143
+ concat(check_box_help_text) unless bootstrap_options.inline?
144
+ concat(generate_error(attribute)) if is_invalid?(attribute) && !bootstrap_options.inline?
139
145
  end
140
146
 
141
147
  check_box_html
@@ -154,8 +160,8 @@ module RailsBootstrapForm
154
160
  radio_button_html = tag.div(class: radio_button_wrapper_class(bootstrap_options)) do
155
161
  concat(radio_button_field)
156
162
  concat(radio_button_label)
157
- concat(radio_button_help_text)
158
- concat(generate_error(attribute)) if is_invalid?(attribute)
163
+ concat(radio_button_help_text) unless bootstrap_options.inline?
164
+ concat(generate_error(attribute)) if is_invalid?(attribute) && !bootstrap_options.inline?
159
165
  end
160
166
 
161
167
  radio_button_html
@@ -177,7 +183,15 @@ module RailsBootstrapForm
177
183
  inputs << check_box(attribute, input_options, input_value, nil)
178
184
  end
179
185
 
180
- inputs
186
+ if options.delete(:include_hidden) { true }
187
+ inputs.prepend hidden_field(attribute, value: "", multiple: true)
188
+ end
189
+
190
+ field_wrapper_builder(attribute, options, html_options) do
191
+ concat(tag.div(class: control_specific_class(:collection_check_boxes)) do
192
+ concat(inputs)
193
+ end)
194
+ end
181
195
  end
182
196
 
183
197
  def collection_radio_buttons(attribute, collection, value_method, text_method, options = {}, html_options = {}, &block)
@@ -198,14 +212,11 @@ module RailsBootstrapForm
198
212
  inputs << radio_button(attribute, input_value, input_options)
199
213
  end
200
214
 
201
- inputs
202
- end
203
-
204
- def collection_input_checked?(checked, obj, input_value)
205
- checked == input_value || Array(checked).try(:include?, input_value) ||
206
- checked == obj || Array(checked).try(:include?, obj)
215
+ field_wrapper_builder(attribute, options, html_options) do
216
+ concat(tag.div(class: control_specific_class(:collection_radio_buttons)) do
217
+ concat(inputs)
218
+ end)
219
+ end
207
220
  end
208
-
209
- private :collection_input_checked?
210
221
  end
211
222
  end
@@ -3,6 +3,6 @@
3
3
  # -*- warn_indent: true -*-
4
4
 
5
5
  module RailsBootstrapForm
6
- VERSION = "0.5.0".freeze
6
+ VERSION = "0.5.1".freeze
7
7
  REQUIRED_RAILS_VERSION = "~> 7.0".freeze
8
8
  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.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harshal LADHE (shivam091)
@@ -122,6 +122,7 @@ files:
122
122
  - lib/rails_bootstrap_form/field_wrapper_builder.rb
123
123
  - lib/rails_bootstrap_form/input_group_builder.rb
124
124
  - lib/rails_bootstrap_form/inputs.rb
125
+ - lib/rails_bootstrap_form/inputs/base.rb
125
126
  - lib/rails_bootstrap_form/version.rb
126
127
  - sig/rails_bootstrap_form.rbs
127
128
  homepage: https://github.com/shivam091/rails_bootstrap_form