pxs-forms 0.0.9 → 0.0.10
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/lib/pxs/forms/model_form_builder.rb +10 -21
- data/lib/pxs/forms/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: efd3c44a4990b55513ce3a025fa5a3e763667733668cdc3ecbd16859fec1629a
|
4
|
+
data.tar.gz: c3274a8654d27e4785b4ae937218dc5c48f12e283038b052ccaaf385df94c91b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9eb444f40f1f9b869c29a2dfdb64f7206ea546f557296c880a704ce1d2f0d8ed5a3e1e2eef316dfdfafbcedf38735cf9df765d33e98cdf7ceba485ea3693b85
|
7
|
+
data.tar.gz: b529cad7defd4dc231af3a7e77324a54e7fb03c9c7df3ee2bf475f85dc6ec8410ca59d9d81ceb08b1d8d70ca9a942118177e5b8b5a527c111e8a242636fc1d86
|
@@ -2,30 +2,22 @@ class ModelFormBuilder < ActionView::Helpers::FormBuilder
|
|
2
2
|
|
3
3
|
delegate :tag, :safe_join, to: :@template
|
4
4
|
|
5
|
-
# define a model field
|
6
|
-
# the format is deduced from the column type or attribute name
|
7
5
|
def field(attribute, options = {})
|
8
6
|
@form_options = options
|
9
|
-
|
10
|
-
# extract the object type from the attribute
|
11
7
|
object_type = object_type_for_attribute(attribute)
|
12
8
|
|
13
|
-
# set the input type depending on the attribute type
|
14
9
|
input_type = case object_type
|
15
10
|
when :date then :string
|
16
11
|
when :integer then :string
|
17
12
|
else object_type
|
18
13
|
end
|
19
14
|
|
20
|
-
# if as: :input_type is set, use it to set input type
|
21
15
|
override_input_type = if options[:as]
|
22
16
|
options[:as]
|
23
|
-
# for collections, use a Select
|
24
17
|
elsif options[:collection]
|
25
18
|
:select
|
26
19
|
end
|
27
20
|
|
28
|
-
# return result of [input_type]_input method
|
29
21
|
send("#{override_input_type || input_type}_input", attribute, options)
|
30
22
|
end
|
31
23
|
|
@@ -57,7 +49,7 @@ class ModelFormBuilder < ActionView::Helpers::FormBuilder
|
|
57
49
|
field_block(attribute, options) do
|
58
50
|
safe_join [
|
59
51
|
(field_label(attribute, options[:label]) unless options[:label] == false),
|
60
|
-
string_field(attribute, merge_input_options({class: "
|
52
|
+
string_field(attribute, merge_input_options({class: "#{"is-invalid" if has_error?(attribute)}"}, options)),
|
61
53
|
]
|
62
54
|
end
|
63
55
|
end
|
@@ -66,18 +58,17 @@ class ModelFormBuilder < ActionView::Helpers::FormBuilder
|
|
66
58
|
field_block(attribute, options) do
|
67
59
|
safe_join [
|
68
60
|
(field_label(attribute, options[:label]) unless options[:label] == false),
|
69
|
-
text_area(attribute, merge_input_options({class: "
|
61
|
+
text_area(attribute, merge_input_options({class: "#{"is-invalid" if has_error?(attribute)}"}, options)),
|
70
62
|
]
|
71
63
|
end
|
72
64
|
end
|
73
65
|
|
74
66
|
def boolean_input(attribute, options = {})
|
75
|
-
raise 'fuck you piece of shit'
|
76
67
|
field_block(attribute, options) do
|
77
68
|
tag.div(class: "checkbox-field") do
|
78
69
|
safe_join [
|
70
|
+
check_box(attribute, merge_input_options({class: "checkbox-input"}, options)),
|
79
71
|
label(attribute, options[:label], class: "checkbox-label"),
|
80
|
-
check_box(attribute, merge_input_options({class: "checkbox-input"}, options[:input_html])),
|
81
72
|
]
|
82
73
|
end
|
83
74
|
end
|
@@ -94,16 +85,14 @@ class ModelFormBuilder < ActionView::Helpers::FormBuilder
|
|
94
85
|
|
95
86
|
def select_input(attribute, options = {})
|
96
87
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
text_method = options[:text_method] || :name
|
101
|
-
input_options = options[:input_html] || {}
|
88
|
+
value_method = options[:value_method] || :to_s
|
89
|
+
text_method = options[:text_method] || :to_s
|
90
|
+
input_options = options || {}
|
102
91
|
|
103
92
|
multiple = input_options[:multiple]
|
104
93
|
|
105
94
|
collection_input(attribute, options) do
|
106
|
-
collection_select(attribute, options[:collection], value_method, text_method, options, merge_input_options({class: "#{"custom-select" unless multiple}
|
95
|
+
collection_select(attribute, options[:collection], value_method, text_method, options, merge_input_options({class: "#{"custom-select" unless multiple} #{"is-invalid" if has_error?(attribute)}"}, options))
|
107
96
|
end
|
108
97
|
end
|
109
98
|
|
@@ -111,7 +100,7 @@ class ModelFormBuilder < ActionView::Helpers::FormBuilder
|
|
111
100
|
|
112
101
|
# We probably need to go back later and adjust this for more customization
|
113
102
|
collection_input(attribute, options) do
|
114
|
-
grouped_collection_select(attribute, options[:collection], :last, :first, :to_s, :to_s, options, merge_input_options({class: "custom-select
|
103
|
+
grouped_collection_select(attribute, options[:collection], :last, :first, :to_s, :to_s, options, merge_input_options({class: "custom-select #{"is-invalid" if has_error?(attribute)}"}, options))
|
115
104
|
end
|
116
105
|
end
|
117
106
|
|
@@ -177,7 +166,7 @@ class ModelFormBuilder < ActionView::Helpers::FormBuilder
|
|
177
166
|
end
|
178
167
|
|
179
168
|
def field_block(attribute, options = {}, &block)
|
180
|
-
tag.div class: "field #{attribute}"
|
169
|
+
tag.div class: "field #{attribute}" do
|
181
170
|
safe_join [
|
182
171
|
block.call,
|
183
172
|
hint_text(options[:hint]),
|
@@ -198,7 +187,7 @@ class ModelFormBuilder < ActionView::Helpers::FormBuilder
|
|
198
187
|
|
199
188
|
def error_text(attribute)
|
200
189
|
if has_error? attribute
|
201
|
-
tag.div @object.errors[
|
190
|
+
tag.div @object.errors[method].join("<br />").html_safe, class: "form-errors"
|
202
191
|
end
|
203
192
|
end
|
204
193
|
|
data/lib/pxs/forms/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pxs-forms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Poubelle
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-04-
|
11
|
+
date: 2024-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|