effective_bootstrap 0.7.4 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -0
  3. data/app/helpers/effective_bootstrap_helper.rb +1 -1
  4. data/app/helpers/effective_form_builder_helper.rb +16 -13
  5. data/app/models/effective/form_builder.rb +5 -1
  6. data/app/models/effective/form_input.rb +4 -2
  7. data/app/models/effective/form_inputs/clear.rb +1 -1
  8. data/app/models/effective/form_inputs/collection_input.rb +1 -1
  9. data/app/models/effective/form_inputs/date_field.rb +2 -1
  10. data/app/models/effective/form_inputs/datetime_field.rb +2 -1
  11. data/app/models/effective/form_inputs/delete.rb +5 -1
  12. data/app/models/effective/form_inputs/email_cc_field.rb +1 -1
  13. data/app/models/effective/form_inputs/email_field.rb +1 -1
  14. data/app/models/effective/form_inputs/error_field.rb +1 -1
  15. data/app/models/effective/form_inputs/file_field.rb +1 -0
  16. data/app/models/effective/form_inputs/float_field.rb +6 -1
  17. data/app/models/effective/form_inputs/hidden_field.rb +11 -0
  18. data/app/models/effective/form_inputs/integer_field.rb +1 -1
  19. data/app/models/effective/form_inputs/number_text_field.rb +1 -1
  20. data/app/models/effective/form_inputs/password_field.rb +1 -1
  21. data/app/models/effective/form_inputs/percent_field.rb +1 -1
  22. data/app/models/effective/form_inputs/phone_field.rb +1 -1
  23. data/app/models/effective/form_inputs/price_field.rb +1 -1
  24. data/app/models/effective/form_inputs/select.rb +3 -3
  25. data/app/models/effective/form_inputs/static_field.rb +1 -1
  26. data/app/models/effective/form_inputs/text_area.rb +1 -1
  27. data/app/models/effective/form_inputs/time_field.rb +2 -1
  28. data/app/models/effective/form_inputs/url_field.rb +1 -1
  29. data/lib/effective_bootstrap/version.rb +1 -1
  30. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c17d12fa1cdbbf137c2ceeadd2706db1585a4ffff943af7eb94eab2ce7901b3
4
- data.tar.gz: 740cf700d5cda6a9befc85ab28f9155c359e71d7a53a838b7a10879420ef5ab4
3
+ metadata.gz: d221a2264a9a64787ad5a179b836fc0c6fbc1cb7b3ea3a968af87eeb708a4b14
4
+ data.tar.gz: 33f8635737e17de6393c39a899293e8696ef4d5e2726d3cf9d1fcc29bfec890c
5
5
  SHA512:
6
- metadata.gz: 0d3ef5647d976c17ec55672041e646455e5f415eb26236539ddd60a5e724be1c87fe80b95755b743ad5d7eec04ff1b3572abaeb6924c0a3b8a67c85139ce07cc
7
- data.tar.gz: 9c2d35ebb17967f306cf8fbd8c4b75772851598cbefbdc808f5b8d91123c396adf37d8efa30530d20f37b09d597d9868abd2df486d7bac5886cb54c084d0f474
6
+ metadata.gz: 0704a3f0bc5866589d8117dd10955978e20c36a5938fcd674a5f148868af9a9fa90d4a93b95df8944771a7b147473517fe98838330fa4fd6c469acd48e2f06c7
7
+ data.tar.gz: cd48f3bd938979dfb1dbbec28d0a0285fd101b2140b7301feb07d5a44fd0d5da2761f08e85b4148f2c615ef4ccc429a455e38e54efd80f1d7a17973242a72a55
data/README.md CHANGED
@@ -229,6 +229,8 @@ As well, you can specify `layout: :vertical`, `layout: :horizontal`, or `layout:
229
229
 
230
230
  The default is `layout: :vertical`.
231
231
 
232
+ If you would like each form and its fields to have unique ids, use `unique_ids: true`.
233
+
232
234
  All standard form fields have been implemented as per [Rails 5.1 FormHelper](http://api.rubyonrails.org/v5.1/classes/ActionView/Helpers/FormHelper.html)
233
235
 
234
236
  When working as a `remote: true` form, you can also pass `flash_success: true|false` and `flash_error: true|false` to control the flash behaviour. By default, the errors will be displayed, and the success will be hidden.
@@ -121,7 +121,7 @@ module EffectiveBootstrapHelper
121
121
  def dots(options = nil, &block)
122
122
  (options ||= {})[:class] = "dropdown dropdown-dots #{options.delete(:class)}".strip
123
123
 
124
- content_tag(:span, options) do
124
+ content_tag(:div, options) do
125
125
  content_tag(:button, class: "btn btn-dots dropdown-toggle #{options.delete(:button_class)}", 'aria-expanded': true, 'aria-haspopup': true, 'data-toggle': 'dropdown', type: 'button') do
126
126
  end + content_tag(:div, capture(&block), class: 'dropdown-menu')
127
127
  end
@@ -1,9 +1,9 @@
1
1
  module EffectiveFormBuilderHelper
2
2
  def effective_form_with(**options, &block)
3
-
4
3
  # Compute the default ID
5
4
  subject = Array(options[:scope] || options[:model]).last
6
5
  class_name = subject.class.name.underscore
6
+ unique_id = options.except(:model).hash.abs
7
7
 
8
8
  html_id = if subject.kind_of?(Symbol)
9
9
  subject.to_s
@@ -14,9 +14,6 @@ module EffectiveFormBuilderHelper
14
14
  end
15
15
 
16
16
  options[:html] = (options[:html] || {}).merge(novalidate: true, onsubmit: 'return EffectiveForm.validate(this)')
17
-
18
- remote_index = options.except(:model).hash.abs
19
-
20
17
  options[:local] = true unless options.key?(:local)
21
18
 
22
19
  if respond_to?(:inline_datatable?) && inline_datatable?
@@ -33,21 +30,27 @@ module EffectiveFormBuilderHelper
33
30
  ('hide-flash-danger' if options[:remote] && options.key?(:flash_error) && !options[:flash_error])
34
31
  ].compact.join(' ')
35
32
 
36
- if options.delete(:remote) == true
37
- @_effective_remote_index ||= {}
38
- remote_index = remote_index + 1 if @_effective_remote_index[remote_index]
33
+ if options[:remote] || options[:unique_ids]
34
+ @_effective_unique_id ||= {}
35
+
36
+ if @_effective_unique_id.key?(unique_id)
37
+ unique_id = unique_id + @_effective_unique_id.length
38
+ end
39
39
 
40
+ options[:unique_id] = unique_id
41
+ html_id = "#{html_id}_#{unique_id}"
42
+
43
+ @_effective_unique_id[unique_id] = true
44
+ end
45
+
46
+ if options.delete(:remote) == true
40
47
  if options[:html][:data].kind_of?(Hash)
41
48
  options[:html][:data][:remote] = true
42
- options[:html][:data]['data-remote-index'] = remote_index
49
+ options[:html][:data]['data-remote-index'] = unique_id
43
50
  else
44
51
  options[:html]['data-remote'] = true
45
- options[:html]['data-remote-index'] = remote_index
52
+ options[:html]['data-remote-index'] = unique_id
46
53
  end
47
-
48
- html_id = "#{html_id}_#{remote_index}"
49
-
50
- @_effective_remote_index[remote_index] = true
51
54
  end
52
55
 
53
56
  # Assign default ID
@@ -20,6 +20,7 @@ module Effective
20
20
  alias_method :super_number_field, :number_field
21
21
  alias_method :super_text_field, :text_field
22
22
  alias_method :super_text_area, :text_area
23
+ alias_method :super_hidden_field, :hidden_field
23
24
 
24
25
  def clear(name = 'Clear', options = {})
25
26
  (options = name; name = 'Clear') if name.kind_of?(Hash)
@@ -85,6 +86,10 @@ module Effective
85
86
  Effective::FormInputs::FormGroup.new(name, options, builder: self).to_html(&block)
86
87
  end
87
88
 
89
+ def hidden_field(name = nil, options = {})
90
+ Effective::FormInputs::HiddenField.new(name, options, builder: self).to_html
91
+ end
92
+
88
93
  def integer_field(name, options = {})
89
94
  Effective::FormInputs::IntegerField.new(name, options, builder: self).to_html
90
95
  end
@@ -196,4 +201,3 @@ module Effective
196
201
 
197
202
  end
198
203
  end
199
-
@@ -24,7 +24,7 @@ module Effective
24
24
  end
25
25
 
26
26
  def input_html_options
27
- { class: 'form-control' }
27
+ { class: 'form-control', id: tag_id }
28
28
  end
29
29
 
30
30
  def input_js_options
@@ -408,7 +408,7 @@ module Effective
408
408
 
409
409
  # https://github.com/rails/rails/blob/master/actionview/lib/action_view/helpers/tags/base.rb#L120
410
410
  def tag_id(index = nil)
411
- case
411
+ id = case
412
412
  when @builder.object_name.empty?
413
413
  sanitized_method_name.dup
414
414
  when index
@@ -416,6 +416,8 @@ module Effective
416
416
  else
417
417
  "#{sanitized_object_name}_#{sanitized_method_name}"
418
418
  end.downcase.parameterize
419
+
420
+ @builder.options[:unique_ids] ? "#{id}_#{@builder.options[:unique_id]}" : id
419
421
  end
420
422
 
421
423
  def sanitized_object_name
@@ -9,7 +9,7 @@ module Effective
9
9
  end
10
10
 
11
11
  def input_html_options
12
- { class: 'btn btn-primary', type: 'clear' }
12
+ { class: 'btn btn-primary', type: 'clear', id: tag_id }
13
13
  end
14
14
 
15
15
  def icon_name
@@ -36,7 +36,7 @@ module Effective
36
36
 
37
37
  @collection_options = {
38
38
  checked: [checked, selected, polymorphic_value, value].find { |value| value != nil },
39
- selected: [selected, checked, polymorphic_value, value].find { |value| value != nil },
39
+ selected: ([selected, checked, polymorphic_value, value].find { |value| value != nil } unless kind_of?(Effective::FormInputs::Radios)),
40
40
  include_blank: include_blank
41
41
  }.compact
42
42
  end
@@ -5,7 +5,8 @@ module Effective
5
5
  def input_html_options
6
6
  {
7
7
  class: ['form-control', 'effective_date_time_picker', 'effective_date', ('not-date-linked' if not_date_linked?)].compact.join(' '),
8
- pattern: pattern
8
+ pattern: pattern,
9
+ id: tag_id
9
10
  }
10
11
  end
11
12
 
@@ -5,7 +5,8 @@ module Effective
5
5
  def input_html_options
6
6
  {
7
7
  class: ['form-control', 'effective_date_time_picker', 'effective_datetime', ('not-date-linked' if not_date_linked?)].compact.join(' '),
8
- pattern: pattern
8
+ pattern: pattern,
9
+ id: tag_id
9
10
  }
10
11
  end
11
12
 
@@ -14,7 +14,11 @@ module Effective
14
14
  end
15
15
 
16
16
  def input_html_options
17
- { class: 'btn btn-warning', data: { method: :delete, remote: true, confirm: "Really delete<br>#{object}?".html_safe } }
17
+ {
18
+ class: 'btn btn-warning',
19
+ id: tag_id,
20
+ data: { method: :delete, remote: true, confirm: "Really delete<br>#{object}?".html_safe }
21
+ }
18
22
  end
19
23
 
20
24
  def border?
@@ -7,7 +7,7 @@ module Effective
7
7
  end
8
8
 
9
9
  def input_html_options
10
- { class: 'form-control', placeholder: 'one@example.com,two@example.com' }
10
+ { class: 'form-control', placeholder: 'one@example.com,two@example.com', id: tag_id }
11
11
  end
12
12
 
13
13
  def input_group_options
@@ -3,7 +3,7 @@ module Effective
3
3
  class EmailField < Effective::FormInput
4
4
 
5
5
  def input_html_options
6
- { class: 'form-control', placeholder: 'someone@example.com' }
6
+ { class: 'form-control', placeholder: 'someone@example.com', id: tag_id }
7
7
  end
8
8
 
9
9
  def input_group_options
@@ -3,7 +3,7 @@ module Effective
3
3
  class ErrorField < Effective::FormInput
4
4
 
5
5
  def input_html_options
6
- { class: 'alert alert-danger' }
6
+ { class: 'alert alert-danger', id: tag_id }
7
7
  end
8
8
 
9
9
  def to_html(&block)
@@ -15,6 +15,7 @@ module Effective
15
15
 
16
16
  def input_html_options
17
17
  {
18
+ id: tag_id,
18
19
  class: 'form-control form-control-file btn-outline-secondary',
19
20
  multiple: multiple?,
20
21
  direct_upload: true,
@@ -7,7 +7,12 @@ module Effective
7
7
  end
8
8
 
9
9
  def input_html_options
10
- { class: 'form-control effective_float', autocomplete: 'off', step: '0.01' }
10
+ {
11
+ class: 'form-control effective_float',
12
+ autocomplete: 'off',
13
+ step: '0.01',
14
+ id: tag_id
15
+ }
11
16
  end
12
17
 
13
18
  # This has gotta be a valid pattern
@@ -0,0 +1,11 @@
1
+ module Effective
2
+ module FormInputs
3
+ class HiddenField < Effective::FormInput
4
+
5
+ def to_html(&block)
6
+ @builder.super_hidden_field(name, options[:input].except(:class, :required))
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -7,7 +7,7 @@ module Effective
7
7
  end
8
8
 
9
9
  def input_html_options
10
- { class: 'form-control effective_integer', autocomplete: 'off' }
10
+ { class: 'form-control effective_integer', autocomplete: 'off', id: tag_id }
11
11
  end
12
12
 
13
13
  def value_to_i
@@ -7,7 +7,7 @@ module Effective
7
7
  end
8
8
 
9
9
  def input_html_options
10
- { class: 'form-control effective_number_text', autocomplete: 'off' }
10
+ { class: 'form-control effective_number_text', autocomplete: 'off', id: tag_id }
11
11
  end
12
12
 
13
13
  end
@@ -3,7 +3,7 @@ module Effective
3
3
  class PasswordField < Effective::FormInput
4
4
 
5
5
  def input_html_options
6
- { class: 'form-control' }
6
+ { class: 'form-control', id: tag_id }
7
7
  end
8
8
 
9
9
  def input_group_options
@@ -12,7 +12,7 @@ module Effective
12
12
  end
13
13
 
14
14
  def input_html_options
15
- { class: 'form-control effective_percent', autocomplete: 'off' }
15
+ { class: 'form-control effective_percent', autocomplete: 'off', id: tag_id }
16
16
  end
17
17
 
18
18
  # This has gotta be a valid pattern
@@ -6,7 +6,7 @@ module Effective
6
6
  DEFAULT_CELL_MASK = '(999) 999-9999'
7
7
 
8
8
  def input_html_options
9
- { class: 'form-control effective_phone', placeholder: '(555) 555-5555' }
9
+ { class: 'form-control effective_phone', placeholder: '(555) 555-5555', id: tag_id }
10
10
  end
11
11
 
12
12
  def input_js_options
@@ -12,7 +12,7 @@ module Effective
12
12
  end
13
13
 
14
14
  def input_html_options
15
- { class: 'form-control effective_price', autocomplete: 'off' }
15
+ { class: 'form-control effective_price', autocomplete: 'off', id: tag_id }
16
16
  end
17
17
 
18
18
  private
@@ -57,7 +57,7 @@ module Effective
57
57
  ('disable-open-on-focus' if disable_open_on_focus?),
58
58
  ].compact.join(' ')
59
59
 
60
- { class: classes, multiple: (true if multiple?), include_blank: (true if include_blank?), include_null: include_null }.compact
60
+ { class: classes, multiple: (true if multiple?), include_blank: (true if include_blank?), id: tag_id }.compact
61
61
  end
62
62
 
63
63
  def assign_options_collection!
@@ -142,7 +142,7 @@ module Effective
142
142
  def no_results
143
143
  return @no_results unless @no_results.nil?
144
144
 
145
- @no_results = options.delete(:no_results)
145
+ @no_results = options.delete(:no_results)
146
146
 
147
147
  if freeform?
148
148
  @no_results ||= 'No results. To create a new one, press ENTER after typing your own free form response.'
@@ -160,7 +160,7 @@ module Effective
160
160
  obj = options.delete(:placeholder)
161
161
 
162
162
  @placeholder = case obj
163
- when nil then
163
+ when nil then
164
164
  (freeform? ? 'Choose or enter' : 'Please choose')
165
165
  when false then ''
166
166
  else obj
@@ -3,7 +3,7 @@ module Effective
3
3
  class StaticField < Effective::FormInput
4
4
 
5
5
  def input_html_options
6
- { class: 'form-control-plaintext', readonly: false }
6
+ { class: 'form-control-plaintext', readonly: false, id: tag_id }
7
7
  end
8
8
 
9
9
  def feedback_options
@@ -3,7 +3,7 @@ module Effective
3
3
  class TextArea < Effective::FormInput
4
4
 
5
5
  def input_html_options
6
- { class: 'form-control', rows: 3 }
6
+ { class: 'form-control', rows: 3, id: tag_id }
7
7
  end
8
8
 
9
9
  end
@@ -5,7 +5,8 @@ module Effective
5
5
  def input_html_options
6
6
  {
7
7
  class: ['form-control', 'effective_date_time_picker', 'effective_time', ('not-date-linked' if not_date_linked?)].compact.join(' '),
8
- pattern: pattern
8
+ pattern: pattern,
9
+ id: tag_id
9
10
  }
10
11
  end
11
12
 
@@ -3,7 +3,7 @@ module Effective
3
3
  class UrlField < Effective::FormInput
4
4
 
5
5
  def input_html_options
6
- { class: 'form-control', placeholder: 'https://www.example.com' }
6
+ { class: 'form-control', placeholder: 'https://www.example.com', id: tag_id }
7
7
  end
8
8
 
9
9
  def input_group_options
@@ -1,3 +1,3 @@
1
1
  module EffectiveBootstrap
2
- VERSION = '0.7.4'.freeze
2
+ VERSION = '0.8.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_bootstrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.4
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-28 00:00:00.000000000 Z
11
+ date: 2020-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -609,6 +609,7 @@ files:
609
609
  - app/models/effective/form_inputs/file_field.rb
610
610
  - app/models/effective/form_inputs/float_field.rb
611
611
  - app/models/effective/form_inputs/form_group.rb
612
+ - app/models/effective/form_inputs/hidden_field.rb
612
613
  - app/models/effective/form_inputs/integer_field.rb
613
614
  - app/models/effective/form_inputs/number_field.rb
614
615
  - app/models/effective/form_inputs/number_text_field.rb