form_props 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6f36ab347fd2b8b9d118ac1d4756f18b9934ff03b0016edfdbc61b1fa01d3a61
4
- data.tar.gz: 823dfb6b47b5fc418e37cde6642ea3dafef38c74149f30b51dc8218647e5ccf9
3
+ metadata.gz: 90a1bcba67478294801b8ede3004d15a41d78eafa3cd7b55a2d533749979c887
4
+ data.tar.gz: 1cceaf16df12dad4a4570809a745fca0046c2d616e44a2fb1bce374a83e71c03
5
5
  SHA512:
6
- metadata.gz: a4b854fba57f47c833142bb229c19447f5e2d19d12e1162c3c718a54c53ead2d4e5aa5cb084c48dee40b70b249aae1613017ec7c3116fbb149e4723075703632
7
- data.tar.gz: df34fc8fea47afcc3d0e7c1492b7c8ef359bfc5f5c37507f98855e524dd13fac1e9dc81d5c09dbcbec615be3c857affd2e185671cecba4c21768516535b33604
6
+ metadata.gz: b92a397b40ac479f7c54a8488b0134b7cdba4ce82cf0c581362134b06aea46ed24e8bfefda33f38b188e79c17c9214e39f6fd5c525c7892e11588e6cd149f9d3
7
+ data.tar.gz: ac20f5814f8c0298758164dc6f26fa7b4a0ab793a4210d5f8bfda27ba10cf6f0c8aefe438b65539863342f1adc35fb67fc3159171141fcb26dfc4f0a55066020
data/README.md CHANGED
@@ -1,11 +1,11 @@
1
- # Form Props
1
+ # form_props
2
2
 
3
3
  ![Build Status](https://github.com/thoughtbot/form_props/actions/workflows/build.yml/badge.svg?branch=main)
4
4
 
5
- FormProps is a Rails form builder that outputs HTML props instead of tags. Now
5
+ form_props is a Rails form builder that outputs HTML props instead of tags. Now
6
6
  you can enjoy the power and convenience of Rails helpers in React!
7
7
 
8
- By separting attributes from tags, FormProps can offer greater flexbility than normal
8
+ By separting attributes from tags, form_props can offer greater flexbility than normal
9
9
  Rails form builders; allowing designers to stay longer in HTML land and more easily
10
10
  customize their form structure without needing to know Rails.
11
11
 
@@ -98,7 +98,7 @@ documentation here reflects that default. You can change that [behavior](https:/
98
98
  if you wish.
99
99
 
100
100
  ## Flexibility
101
- FormProps is only concerned about attributes, the designer can focus on tag
101
+ form_props is only concerned about attributes, the designer can focus on tag
102
102
  structure and stay longer in HTML land. For example, you can decide to nest an
103
103
  input inside a label.
104
104
 
@@ -153,7 +153,7 @@ export default (({props, inputs, extras})) => {
153
153
 
154
154
  ## Error handling
155
155
 
156
- FormProps doesn't handle form errors, but you can easily add this functionality:
156
+ form_props doesn't handle form errors, but you can easily add this functionality:
157
157
 
158
158
  ```ruby
159
159
  json.someForm do
@@ -22,27 +22,6 @@ module FormProps
22
22
  @key || sanitized_method_name.camelize(:lower)
23
23
  end
24
24
 
25
- def add_options(option_tags, options, value = nil)
26
- if options[:include_blank]
27
- content = (options[:include_blank] if options[:include_blank].is_a?(String))
28
- label = (" " unless content)
29
- option_tags = [{label: content || label, value: ""}] + option_tags
30
- end
31
-
32
- if value.blank? && options[:prompt]
33
- tag_options = {value: ""}.tap do |prompt_opts|
34
- prompt_opts[:disabled] = true if options[:disabled] == ""
35
- if options[:selected] == ""
36
- selected_values.push("")
37
- end
38
- prompt_opts[:label] = prompt_text(options[:prompt])
39
- end
40
- option_tags = [tag_options] + option_tags
41
- end
42
-
43
- option_tags
44
- end
45
-
46
25
  def input_props(options)
47
26
  return if options.blank?
48
27
 
@@ -131,41 +110,6 @@ module FormProps
131
110
 
132
111
  tag_values
133
112
  end
134
-
135
- def select_content_props(option_tags, options, html_options)
136
- html_options = html_options.stringify_keys
137
- add_default_name_and_id(html_options)
138
-
139
- if placeholder_required?(html_options)
140
- raise ArgumentError, "include_blank cannot be false for a required field." if options[:include_blank] == false
141
- options[:include_blank] ||= true unless options[:prompt]
142
- end
143
-
144
- html_options["type"] = "select"
145
- value_for_blank = options.fetch(:selected) { value }
146
- option_tags = add_options(option_tags, options, value_for_blank)
147
-
148
- if options[:multiple]
149
- html_options["multiple"] = options[:multiple]
150
- end
151
-
152
- if selected_values.any?
153
- html_options["value"] ||= if html_options["multiple"]
154
- Array(selected_values)
155
- else
156
- selected_values.first
157
- end
158
- end
159
-
160
- json.set!(sanitized_key) do
161
- input_props(html_options)
162
-
163
- if options.key?(:include_hidden)
164
- json.includeHidden options[:include_hidden]
165
- end
166
- json.options(option_tags)
167
- end
168
- end
169
113
  end
170
114
  end
171
115
  end
@@ -6,6 +6,8 @@ module FormProps
6
6
  module Inputs
7
7
  class CollectionCheckBoxes < Base
8
8
  include ActionView::Helpers::Tags::CollectionHelpers
9
+ include ActionView::Helpers::FormOptionsHelper
10
+
9
11
  include CollectionHelpers
10
12
 
11
13
  class CheckBoxBuilder < Builder
@@ -6,6 +6,7 @@ module FormProps
6
6
  module Inputs
7
7
  class CollectionRadioButtons < Base
8
8
  include ActionView::Helpers::Tags::CollectionHelpers
9
+ include ActionView::Helpers::FormOptionsHelper
9
10
  include CollectionHelpers
10
11
 
11
12
  class RadioButtonBuilder < Builder
@@ -2,8 +2,13 @@
2
2
 
3
3
  module FormProps
4
4
  module Inputs
5
- class CollectionSelect < Base # :nodoc:
5
+ class CollectionSelect < Base
6
+ if ActionView::VERSION::STRING >= "7.1"
7
+ include ActionView::Helpers::Tags::SelectRenderer
8
+ end
9
+ include ActionView::Helpers::FormOptionsHelper
6
10
  include FormOptionsHelper
11
+ include SelectRenderer
7
12
 
8
13
  def initialize(object_name, method_name, template_object, collection, value_method, text_method, options, html_options)
9
14
  @collection = collection
@@ -3,7 +3,12 @@
3
3
  module FormProps
4
4
  module Inputs
5
5
  class GroupedCollectionSelect < Base
6
+ if ActionView::VERSION::STRING >= "7.1"
7
+ include ActionView::Helpers::Tags::SelectRenderer
8
+ end
9
+ include ActionView::Helpers::FormOptionsHelper
6
10
  include FormOptionsHelper
11
+ include SelectRenderer
7
12
 
8
13
  def initialize(object_name, method_name, template_object, collection, group_method, group_label_method, option_key_method, option_value_method, options, html_options)
9
14
  @collection = collection
@@ -3,7 +3,12 @@
3
3
  module FormProps
4
4
  module Inputs
5
5
  class Select < Base
6
+ if ActionView::VERSION::STRING >= "7.1"
7
+ include ActionView::Helpers::Tags::SelectRenderer
8
+ end
9
+ include ActionView::Helpers::FormOptionsHelper
6
10
  include FormOptionsHelper
11
+ include SelectRenderer
7
12
 
8
13
  def initialize(object_name, method_name, template_object, choices, options, html_options)
9
14
  @choices = choices
@@ -3,7 +3,12 @@
3
3
  module FormProps
4
4
  module Inputs
5
5
  class TimeZoneSelect < Base
6
+ if ActionView::VERSION::STRING >= "7.1"
7
+ include ActionView::Helpers::Tags::SelectRenderer
8
+ end
9
+ include ActionView::Helpers::FormOptionsHelper
6
10
  include FormOptionsHelper
11
+ include SelectRenderer
7
12
 
8
13
  def initialize(object_name, method_name, template_object, priority_zones, options, html_options)
9
14
  @priority_zones = priority_zones
@@ -3,7 +3,12 @@
3
3
  module FormProps
4
4
  module Inputs
5
5
  class WeekdaySelect < Base
6
+ if ActionView::VERSION::STRING >= "7.1"
7
+ include ActionView::Helpers::Tags::SelectRenderer
8
+ end
9
+ include ActionView::Helpers::FormOptionsHelper
6
10
  include FormOptionsHelper
11
+ include SelectRenderer
7
12
 
8
13
  def initialize(object_name, method_name, template_object, options, html_options)
9
14
  @html_options = html_options
@@ -0,0 +1,59 @@
1
+ module FormProps
2
+ module SelectRenderer
3
+ def add_options(option_tags, options, value = nil)
4
+ if options[:include_blank]
5
+ content = (options[:include_blank] if options[:include_blank].is_a?(String))
6
+ label = (" " unless content)
7
+ option_tags = [{label: content || label, value: ""}] + option_tags
8
+ end
9
+
10
+ if value.blank? && options[:prompt]
11
+ tag_options = {value: ""}.tap do |prompt_opts|
12
+ prompt_opts[:disabled] = true if options[:disabled] == ""
13
+ if options[:selected] == ""
14
+ selected_values.push("")
15
+ end
16
+ prompt_opts[:label] = prompt_text(options[:prompt])
17
+ end
18
+ option_tags = [tag_options] + option_tags
19
+ end
20
+
21
+ option_tags
22
+ end
23
+
24
+ def select_content_props(option_tags, options, html_options)
25
+ html_options = html_options.stringify_keys
26
+ add_default_name_and_id(html_options)
27
+
28
+ if placeholder_required?(html_options)
29
+ raise ArgumentError, "include_blank cannot be false for a required field." if options[:include_blank] == false
30
+ options[:include_blank] ||= true unless options[:prompt]
31
+ end
32
+
33
+ html_options["type"] = "select"
34
+ value_for_blank = options.fetch(:selected) { value }
35
+ option_tags = add_options(option_tags, options, value_for_blank)
36
+
37
+ if options[:multiple]
38
+ html_options["multiple"] = options[:multiple]
39
+ end
40
+
41
+ if selected_values.any?
42
+ html_options["value"] ||= if html_options["multiple"]
43
+ Array(selected_values)
44
+ else
45
+ selected_values.first
46
+ end
47
+ end
48
+
49
+ json.set!(sanitized_key) do
50
+ input_props(html_options)
51
+
52
+ if options.key?(:include_hidden)
53
+ json.includeHidden options[:include_hidden]
54
+ end
55
+ json.options(option_tags)
56
+ end
57
+ end
58
+ end
59
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FormProps
4
- VERSION = "0.0.6"
4
+ VERSION = "0.0.7"
5
5
  end
data/lib/form_props.rb CHANGED
@@ -5,6 +5,7 @@ require "action_pack"
5
5
  require "form_props/helper"
6
6
  require "form_props/action_view_extensions/form_helper"
7
7
  require "form_props/form_options_helper"
8
+ require "form_props/select_renderer"
8
9
  require "form_props/inputs/base"
9
10
  require "form_props/inputs/text_field"
10
11
  require "form_props/inputs/text_area"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: form_props
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johny Ho
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-23 00:00:00.000000000 Z
11
+ date: 2024-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -94,6 +94,7 @@ files:
94
94
  - lib/form_props/inputs/url_field.rb
95
95
  - lib/form_props/inputs/week_field.rb
96
96
  - lib/form_props/inputs/weekday_select.rb
97
+ - lib/form_props/select_renderer.rb
97
98
  - lib/form_props/version.rb
98
99
  homepage: https://github.com/thoughtbot/form_props/
99
100
  licenses: