phlex-forms 0.2.6 → 0.2.8
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 +5 -0
- data/lib/forms/live.rb +7 -1
- data/lib/forms/tag_field.rb +25 -18
- data/lib/phlex_forms/builder.rb +7 -0
- data/lib/phlex_forms/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9e69e13250ea52121abd2e7e16f91e17b63f7e470131d333513037ad57cbb4cb
|
|
4
|
+
data.tar.gz: a5d9179052c02fa4462434d08df73164e5cca3506df42fdd6d5f78852a8cf0ab
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 53ea74ca2f23ad56b79180c453dafb9dd766604dfb380f579b30bb76ca9fd5be957a4b0e77bb9035069074563b25d63b80e1d372057aefda0d7be8cf1eb313ea
|
|
7
|
+
data.tar.gz: dc905da47d50a3a43f83adb65faa3f386dcfbcd70e1d7d25d7e646894f994331eb1c3c309eb666271cf03ef1e182c94a1ea19a2a42515af13d7fb1529ecd77b0
|
data/README.md
CHANGED
|
@@ -227,6 +227,11 @@ f.Checkbox(:terms) ; f.Toggle(:notify) ; f.FileInput(:avatar)
|
|
|
227
227
|
f.Label(:email) ; f.Hidden(:token) ; f.submit("Save", :primary)
|
|
228
228
|
```
|
|
229
229
|
|
|
230
|
+
Migrating from Rails' `FormBuilder`? `f.hidden_field(:token, value: x)` is a
|
|
231
|
+
snake_case alias for `f.Hidden` — same model-bound path, and an explicit
|
|
232
|
+
`value:` wins over the model's current value — so those call sites port over
|
|
233
|
+
verbatim.
|
|
234
|
+
|
|
230
235
|
For a bespoke widget (date picker, tag field, remote select), wrap it in
|
|
231
236
|
`f.Control` and bind through the public helpers — this is the supported path,
|
|
232
237
|
not a fork reason:
|
data/lib/forms/live.rb
CHANGED
|
@@ -168,10 +168,16 @@ module Forms
|
|
|
168
168
|
# widget (rendered in the block) is driven by this root, which then DOM-owns
|
|
169
169
|
# its hidden field. Name/id derived through field_name/field_id — the same
|
|
170
170
|
# path the rootless render uses, so the [name=…]/#…_query selectors match.
|
|
171
|
+
# This form IS a reactive component, so it has reactive_tags/reactive_filter
|
|
172
|
+
# itself — the same 0.12.2 escape-hatch sugar Forms::TagField uses, emitting
|
|
173
|
+
# both filter selectors the client needs (issue #6 Caveats 1 & 2).
|
|
171
174
|
tag = self.class.live_tags_declaration
|
|
172
175
|
return attrs unless tag
|
|
173
176
|
|
|
174
|
-
|
|
177
|
+
query_id = Forms::TagField.query_id(field_id(tag[:name]))
|
|
178
|
+
mix(attrs,
|
|
179
|
+
reactive_tags(name: field_name(tag[:name])),
|
|
180
|
+
reactive_filter(input: "##{query_id}"))
|
|
175
181
|
end
|
|
176
182
|
|
|
177
183
|
# Untouched fields get no error set, so nothing flashes before the user
|
data/lib/forms/tag_field.rb
CHANGED
|
@@ -18,11 +18,13 @@ module Forms
|
|
|
18
18
|
# The reactive_tags_* client helpers require phlex-reactive >= 0.11.4.
|
|
19
19
|
#
|
|
20
20
|
# It uses the reactive_tags_add/option/remove helpers for the chip/query/option
|
|
21
|
-
# behavior,
|
|
22
|
-
# reactive_tags(:
|
|
23
|
-
#
|
|
24
|
-
#
|
|
25
|
-
#
|
|
21
|
+
# behavior, and the ROOT's wire attrs come from the 0.12.2 escape-hatch sugar:
|
|
22
|
+
# reactive_tags(name: @name) takes the per-instance wire name verbatim ("user[tags]")
|
|
23
|
+
# — the class-level reactive_scope compile can't express it — validated at render;
|
|
24
|
+
# reactive_filter(input: "#…_query") targets the query input by id so it never
|
|
25
|
+
# submits, and (unlike the old raw -input-only attr) also emits
|
|
26
|
+
# data-reactive-filter-option so the 0.12.x client type-ahead actually runs
|
|
27
|
+
# (issue #6 Caveats 1 & 2).
|
|
26
28
|
class TagField < Phlex::HTML
|
|
27
29
|
include Phlex::Reactive::ClientBindings
|
|
28
30
|
|
|
@@ -48,21 +50,26 @@ module Forms
|
|
|
48
50
|
end
|
|
49
51
|
end
|
|
50
52
|
|
|
51
|
-
# The
|
|
52
|
-
#
|
|
53
|
-
#
|
|
54
|
-
|
|
55
|
-
# is lifted rootless.
|
|
56
|
-
def self.root_tag_attributes(name:, id:)
|
|
57
|
-
{ data: {
|
|
58
|
-
reactive_tags_field: %([name="#{name}"]),
|
|
59
|
-
reactive_filter_input: "##{id}_query"
|
|
60
|
-
} }
|
|
61
|
-
end
|
|
53
|
+
# The query input's id — the reactive_filter(input:) target and the id the
|
|
54
|
+
# search input itself carries. Public so Forms::Live can derive the same id
|
|
55
|
+
# when it hoists the tag wire attrs onto the <form> root (rootless widget).
|
|
56
|
+
def self.query_id(id) = "#{id}_query"
|
|
62
57
|
|
|
63
58
|
private
|
|
64
59
|
|
|
65
|
-
|
|
60
|
+
# The root's tag wire attrs, via the 0.12.2 escape-hatch sugar (Caveats 1 & 2):
|
|
61
|
+
# reactive_tags(name:) takes the instance-dynamic wire name verbatim and
|
|
62
|
+
# validates it at render; reactive_filter(input:) targets the query input by
|
|
63
|
+
# #id (so it never submits a stray param) and emits both filter selectors the
|
|
64
|
+
# 0.12.x client needs to run the type-ahead. Both are private helpers from
|
|
65
|
+
# ClientBindings — Forms::Live has its own copies (it's a reactive component)
|
|
66
|
+
# and calls them directly when hoisting these onto the <form> root.
|
|
67
|
+
def root_tag_attributes
|
|
68
|
+
mix(
|
|
69
|
+
reactive_tags(name: @name),
|
|
70
|
+
reactive_filter(input: "##{self.class.query_id(@id)}")
|
|
71
|
+
)
|
|
72
|
+
end
|
|
66
73
|
|
|
67
74
|
# The widget body WITHOUT its root wrapper — shared with the rootless variant
|
|
68
75
|
# so chip/template/suggestion markup never drifts between the two.
|
|
@@ -93,7 +100,7 @@ module Forms
|
|
|
93
100
|
|
|
94
101
|
def query_attributes
|
|
95
102
|
{
|
|
96
|
-
id:
|
|
103
|
+
id: self.class.query_id(@id), type: "search", autocomplete: "off",
|
|
97
104
|
placeholder: @placeholder, class: input_classes,
|
|
98
105
|
"aria-invalid": @error || nil
|
|
99
106
|
}.compact
|
data/lib/phlex_forms/builder.rb
CHANGED
|
@@ -175,6 +175,13 @@ module PhlexForms
|
|
|
175
175
|
render field_object(name).hidden(**)
|
|
176
176
|
end
|
|
177
177
|
|
|
178
|
+
# Rails FormBuilder-compatible hidden field, for straight migration of
|
|
179
|
+
# `form.hidden_field(:token, value: x)` call sites. Same model-bound path as
|
|
180
|
+
# `Hidden`; an explicit `value:` wins over the model's current value.
|
|
181
|
+
def hidden_field(name, **)
|
|
182
|
+
render field_object(name).hidden(**)
|
|
183
|
+
end
|
|
184
|
+
|
|
178
185
|
def Label(name, text = nil, *modifiers, **, &)
|
|
179
186
|
render field_object(name).label(text, *modifiers, **, &)
|
|
180
187
|
end
|
data/lib/phlex_forms/version.rb
CHANGED