sdr_view_components 0.11.1 → 0.12.0

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: da67f1cfd2cfb8a85d88d496df552d11e6a5c0648ae0662d4847ee6735aedf04
4
- data.tar.gz: cf355351c20972ad34829bd2565e5363f10bd3b443befdc879ad008dea30ed4a
3
+ metadata.gz: 70bbb057dd95a5fb475b407f387eafc7b8948a59e5ea5a7eb72e56a1facf10e1
4
+ data.tar.gz: c5be40e999590e03fbfbaa4d3a0eb4e52cdbbd83bd5b61b394f568899c574fe8
5
5
  SHA512:
6
- metadata.gz: e2d8ad78b5a7de81672e11e55d0d2a5ce524075ed2317f6917d1b02ed9fb97c64129cb428a74e152fc1cb4ce46cf37c19663a29e03fdf87aed78310aa8a8c2c1
7
- data.tar.gz: e947cae010e6f7d039952b66ab9875609ba19dcd8ccabf0fa8d1aca0eba2f1f6109d44480ea2949136cc7c6fd6b6ad8f84866b4d03879f7951abf129c6ab4ab8
6
+ metadata.gz: 95ad863bdb52830c08d73ff044dcd09279f5f56b0ae5f9ba95a4d08b0cece0b8b09d50d1bda4463eae96e56fd7bcde42e288f4612e3086b357aa17cd9be9ce67
7
+ data.tar.gz: f9beb404a32f5beb693e9014561fe80ec3db9f47d6cec331169e56de2ca8925a15b7f8c22a2464e142d378c460a99e6ebaa872ea4724877daa8449b7371fa668
@@ -15,14 +15,22 @@ module SdrViewComponents
15
15
  end
16
16
 
17
17
  def label_field_name
18
- "#{sanitize(field_name)}_#{sanitize(input_args[:value])}"
18
+ "#{sanitize_method_name(field_name)}_#{sanitize_value(input_args[:value])}"
19
19
  end
20
20
 
21
21
  private
22
22
 
23
- # From https://github.com/rails/rails/blob/main/actionview/lib/action_view/helpers/form_tag_helper.rb
24
- def sanitize(value)
25
- value.to_s.delete(']').tr('^-a-zA-Z0-9:.', '_')
23
+ # The input is rendered by form.radio_button, so the label's for must match the id that
24
+ # ActionView::Helpers::Tags::Base generates. These mirror its sanitized_method_name and
25
+ # sanitized_value. Note this is *not* form_tag_helper.rb's sanitize_to_id, which applies
26
+ # to radio_button_tag and disagrees on uppercase letters, '.', and other non-word chars.
27
+ # From https://github.com/rails/rails/blob/main/actionview/lib/action_view/helpers/tags/base.rb
28
+ def sanitize_method_name(name)
29
+ name.to_s.delete_suffix('?')
30
+ end
31
+
32
+ def sanitize_value(value)
33
+ value.to_s.gsub(/[\s.]/, '_').gsub(/[^-[[:word:]]]/, '').downcase
26
34
  end
27
35
  end
28
36
  end
@@ -1,4 +1,4 @@
1
- <%= form_with(model:, id:, url:, html: { novalidate: true }) do |form| %>
1
+ <%= form_with(model:, id:, url:, html: { novalidate: true, **html_options }) do |form| %>
2
2
  <% hidden_fields.each do |field| %>
3
3
  <%= form.hidden_field field %>
4
4
  <% end %>
@@ -9,15 +9,16 @@ module SdrViewComponents
9
9
  # `url:` is optional and only needed when the model can't derive its own submission url
10
10
  # (e.g. it has no resourceful routes).
11
11
  class HiddenFieldsFormComponent < BaseComponent
12
- def initialize(model:, id:, hidden_fields: [], url: nil)
12
+ def initialize(model:, id:, hidden_fields: [], url: nil, html_options: {})
13
13
  @model = model
14
14
  @id = id
15
15
  @hidden_fields = hidden_fields
16
16
  @url = url
17
+ @html_options = html_options
17
18
  super()
18
19
  end
19
20
 
20
- attr_reader :model, :id, :hidden_fields, :url
21
+ attr_reader :model, :id, :hidden_fields, :url, :html_options
21
22
  end
22
23
  end
23
24
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SdrViewComponents
4
- VERSION = '0.11.1'
4
+ VERSION = '0.12.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sdr_view_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.1
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Collier
@@ -375,7 +375,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
375
375
  - !ruby/object:Gem::Version
376
376
  version: '0'
377
377
  requirements: []
378
- rubygems_version: 4.0.16
378
+ rubygems_version: 4.0.6
379
379
  specification_version: 4
380
380
  summary: Rails gem for providing SDR-specific ViewComponents.
381
381
  test_files: []