form_props 0.0.6 → 0.1.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 +4 -4
- data/README.md +6 -6
- data/lib/form_props/action_view_extensions/form_helper.rb +1 -1
- data/lib/form_props/form_builder.rb +1 -1
- data/lib/form_props/inputs/base.rb +0 -56
- data/lib/form_props/inputs/collection_check_boxes.rb +2 -0
- data/lib/form_props/inputs/collection_radio_buttons.rb +1 -0
- data/lib/form_props/inputs/collection_select.rb +6 -1
- data/lib/form_props/inputs/grouped_collection_select.rb +5 -0
- data/lib/form_props/inputs/select.rb +5 -0
- data/lib/form_props/inputs/time_zone_select.rb +5 -0
- data/lib/form_props/inputs/weekday_select.rb +5 -0
- data/lib/form_props/select_renderer.rb +59 -0
- data/lib/form_props/version.rb +1 -1
- data/lib/form_props.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e27a5343fb9e2ffcc08684bcfc28f6091af55299cfc8cb7a4bc8c142d441fc6d
|
4
|
+
data.tar.gz: dc9e8add0d4afdff58b42bcd495917cc025ac43bf70ff55a385a234168e4a080
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fbd73cafb16f2af98c4521313f4eec24b1dfdf8aa15270960fffc26382cf5992e054ead2a817093f18aae3eb11a75a1d31b1002c43adda5611750042f12aa12
|
7
|
+
data.tar.gz: 4fd151dafc319edcd54db12cfb8909c2eb70c0ae2c638235181d86b0ce5f0a7dbe9a7c052d6097ab9c6d4435a7810fcb1e2ea433b72f564bb3940da8e5d64c11
|
data/README.md
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
#
|
1
|
+
# form_props
|
2
2
|
|
3
3
|

|
4
4
|
|
5
|
-
|
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,
|
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
|
|
@@ -31,7 +31,7 @@ and `bundle install`
|
|
31
31
|
```ruby
|
32
32
|
json.some_form do
|
33
33
|
form_props(@post) do |f|
|
34
|
-
f.
|
34
|
+
f.text_field :title
|
35
35
|
f.submit
|
36
36
|
end
|
37
37
|
end
|
@@ -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
|
-
|
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
|
-
|
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
|
@@ -102,7 +102,7 @@ module FormProps
|
|
102
102
|
end
|
103
103
|
|
104
104
|
def radio_button(method, tag_value, options = {})
|
105
|
-
Inputs::RadioButton.new(@object_name, method, @template, tag_value, options).render
|
105
|
+
Inputs::RadioButton.new(@object_name, method, @template, tag_value, objectify_options(options)).render
|
106
106
|
end
|
107
107
|
|
108
108
|
def collection_select(method, collection, value_method, text_method, options = {}, html_options = {})
|
@@ -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
|
@@ -2,8 +2,13 @@
|
|
2
2
|
|
3
3
|
module FormProps
|
4
4
|
module Inputs
|
5
|
-
class CollectionSelect < Base
|
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
|
data/lib/form_props/version.rb
CHANGED
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
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Johny Ho
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-12-01 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:
|
@@ -114,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
115
|
- !ruby/object:Gem::Version
|
115
116
|
version: '0'
|
116
117
|
requirements: []
|
117
|
-
rubygems_version: 3.
|
118
|
+
rubygems_version: 3.5.22
|
118
119
|
signing_key:
|
119
120
|
specification_version: 4
|
120
121
|
summary: Form props is a Rails form builder that renders form attributes in JSON
|