effective_bootstrap 0.7.4 → 0.8.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -0
  3. data/app/assets/images/icons/microsoft.svg +1 -0
  4. data/app/assets/javascripts/effective_bootstrap/confirm.js.coffee.erb +10 -5
  5. data/app/helpers/effective_bootstrap_helper.rb +6 -4
  6. data/app/helpers/effective_form_builder_helper.rb +16 -13
  7. data/app/models/effective/form_builder.rb +5 -1
  8. data/app/models/effective/form_input.rb +5 -3
  9. data/app/models/effective/form_inputs/clear.rb +1 -1
  10. data/app/models/effective/form_inputs/collection_input.rb +1 -1
  11. data/app/models/effective/form_inputs/date_field.rb +2 -1
  12. data/app/models/effective/form_inputs/datetime_field.rb +2 -1
  13. data/app/models/effective/form_inputs/delete.rb +5 -1
  14. data/app/models/effective/form_inputs/email_cc_field.rb +1 -1
  15. data/app/models/effective/form_inputs/email_field.rb +1 -1
  16. data/app/models/effective/form_inputs/error_field.rb +1 -1
  17. data/app/models/effective/form_inputs/file_field.rb +2 -1
  18. data/app/models/effective/form_inputs/float_field.rb +6 -1
  19. data/app/models/effective/form_inputs/hidden_field.rb +11 -0
  20. data/app/models/effective/form_inputs/integer_field.rb +1 -1
  21. data/app/models/effective/form_inputs/number_text_field.rb +1 -1
  22. data/app/models/effective/form_inputs/password_field.rb +1 -1
  23. data/app/models/effective/form_inputs/percent_field.rb +1 -1
  24. data/app/models/effective/form_inputs/phone_field.rb +1 -1
  25. data/app/models/effective/form_inputs/price_field.rb +1 -1
  26. data/app/models/effective/form_inputs/select.rb +3 -3
  27. data/app/models/effective/form_inputs/static_field.rb +1 -1
  28. data/app/models/effective/form_inputs/text_area.rb +1 -1
  29. data/app/models/effective/form_inputs/time_field.rb +2 -1
  30. data/app/models/effective/form_inputs/url_field.rb +1 -1
  31. data/lib/effective_bootstrap/version.rb +1 -1
  32. metadata +4 -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: fd2b4a321ad92d428321ae94d2b26875a047f209c3b3842ca4f4be921b76071d
4
+ data.tar.gz: fe91e9b1898dfb4286470bacf83b7ab09f12b091aa1218109d432c330f991493
5
5
  SHA512:
6
- metadata.gz: 0d3ef5647d976c17ec55672041e646455e5f415eb26236539ddd60a5e724be1c87fe80b95755b743ad5d7eec04ff1b3572abaeb6924c0a3b8a67c85139ce07cc
7
- data.tar.gz: 9c2d35ebb17967f306cf8fbd8c4b75772851598cbefbdc808f5b8d91123c396adf37d8efa30530d20f37b09d597d9868abd2df486d7bac5886cb54c084d0f474
6
+ metadata.gz: 99b921f38e9cc727b520012cb0b4621c127c51dde6491ee69ad297060368af741df1a9b8df83141ff8a84007ffab0f8484e66c53bf03ae0796b1bc1782b6d4bf
7
+ data.tar.gz: 03422e1c8f7ab703916ce5a0473266d23560e4ad485306acf01aecb387ca4b94a390b3d87b0f6cd7b282a74a4a634755c0f39889c4f198992512efbbd973e67b
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.
@@ -0,0 +1 @@
1
+ <svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Microsoft Azure icon</title><path d="M5.483 21.3H24L14.025 4.013l-3.038 8.347 5.836 6.938L5.483 21.3zM13.23 2.7L6.105 8.677 0 19.253h5.505v.014L13.23 2.7z"/></svg>
@@ -1,6 +1,6 @@
1
- # These next three methods hijack jquery_ujs data-confirm and do it our own way with a double click confirm
1
+ # These next three methods hijack rails/ujs and jquery_ujs data-confirm and do it our own way with a double click confirm
2
2
 
3
- if <%= !!EffectiveBootstrap.use_custom_data_confirm %> && $.rails
3
+ if <%= !!EffectiveBootstrap.use_custom_data_confirm %> && (window.Rails || $.rails)
4
4
  $(document).on 'confirm', (event) ->
5
5
  $obj = $(event.target)
6
6
 
@@ -18,6 +18,11 @@ if <%= !!EffectiveBootstrap.use_custom_data_confirm %> && $.rails
18
18
  , 4000)
19
19
  false # don't show the confirmation dialog
20
20
 
21
- $.rails.confirm = (message) -> true
22
- $.rails.effective_bootstrap_custom_data_confirm = true
23
- $(document).on 'confirm:complete', (event) -> $(event.target).data('confirmed')
21
+ (window.Rails || $.rails).confirm = (message) -> true
22
+ (window.Rails || $.rails).effective_bootstrap_custom_data_confirm = true
23
+
24
+ $(document).on 'confirm:complete', (event) -> $(event.target).data('confirmed')
25
+
26
+ $(document).on 'click', 'a.dropdown-item[data-confirm]', (event) ->
27
+ event.preventDefault()
28
+ false
@@ -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
@@ -154,11 +154,13 @@ module EffectiveBootstrapHelper
154
154
  end
155
155
 
156
156
  # Works with dots ao and dropdown do
157
- def dropdown_divider
157
+ def dropdown_divider(options = {})
158
+ options[:class] = [options[:class], 'dropdown-divider'].compact.join(' ')
159
+
158
160
  unless @_dropdown_link_tos
159
- content_tag(:div, '', class: 'dropdown-divider')
161
+ content_tag(:div, '', options)
160
162
  else
161
- @_dropdown_link_tos << content_tag(:div, '', class: 'dropdown-divider')
163
+ @_dropdown_link_tos << content_tag(:div, '', options)
162
164
  nil
163
165
  end
164
166
  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
-
@@ -7,7 +7,7 @@ module Effective
7
7
  EXCLUSIVE_CLASS_SUFFIXES = ['-primary', '-secondary', '-success', '-danger', '-warning', '-info', '-light', '-dark']
8
8
 
9
9
  delegate :object, to: :@builder
10
- delegate :capture, :content_tag, :link_to, :icon, :asset_path, to: :@template
10
+ delegate :capture, :content_tag, :image_tag, :link_to, :icon, :asset_path, to: :@template
11
11
 
12
12
  # So this takes in the options for an entire form group.
13
13
  def initialize(name, options, builder:, html_options: nil)
@@ -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,
@@ -93,7 +94,7 @@ module Effective
93
94
  content_tag(:div, class: 'card mb-3') do
94
95
  if attachment.image?
95
96
  content_tag(:div, class: 'card-body') do
96
- content_tag(:img, '', class: 'img-fluid', src: url, alt: attachment.filename.to_s) +
97
+ image_tag(url, alt: attachment.filename.to_s, class: 'img-fluid') +
97
98
  link_to(attachment.filename, url, class: 'card-link')
98
99
  end
99
100
  else
@@ -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.4'.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.4
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-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -262,6 +262,7 @@ files:
262
262
  - app/assets/images/icons/message-square.svg
263
263
  - app/assets/images/icons/mic-off.svg
264
264
  - app/assets/images/icons/mic.svg
265
+ - app/assets/images/icons/microsoft.svg
265
266
  - app/assets/images/icons/minimize-2.svg
266
267
  - app/assets/images/icons/minimize.svg
267
268
  - app/assets/images/icons/minus-circle.svg
@@ -609,6 +610,7 @@ files:
609
610
  - app/models/effective/form_inputs/file_field.rb
610
611
  - app/models/effective/form_inputs/float_field.rb
611
612
  - app/models/effective/form_inputs/form_group.rb
613
+ - app/models/effective/form_inputs/hidden_field.rb
612
614
  - app/models/effective/form_inputs/integer_field.rb
613
615
  - app/models/effective/form_inputs/number_field.rb
614
616
  - app/models/effective/form_inputs/number_text_field.rb