phlex-forms 0.2.6 → 0.2.7

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: fd321ccbe2bec3d9b8966d0eda0e1036e4143af38b4aa55dec702ce8c6d23137
4
- data.tar.gz: 2abe25e3c63dd5d689a6c6d762df3ed6204c0dca0ef6b7d569f6e8c3da4ee1d7
3
+ metadata.gz: d963c5c0eb08c6027d236da0489af8e2b7fd5ef258092c91cc280c8fe4711c5e
4
+ data.tar.gz: d1a686ce5b6b249c3860584c8b7a9447e4198efe7d0b6c9aed86441a3d7ee915
5
5
  SHA512:
6
- metadata.gz: fb8b8768817fef4b18e0dacadbfb966cf7356339badfce5e96ea04ccc7e0d5bcc60686e65288413376bbe7873e17993746b35dceefb917a58132505ef88f9094
7
- data.tar.gz: e7f775c0c15db6e595f9ac5c93449fb49b12d032f1a615f231b5e23f1aa2ac188fb2eb21a6afccf073758227a3e100a69def8f24185baadd63ddc19e923a48e0
6
+ metadata.gz: 4563f81fac25d23e76303ee2c96f2734add870c5b5707b8d45683a62479fccc30d0cd36464492627bb7bbabba209f41df8d657514d37a7fd748715d1af3150ab
7
+ data.tar.gz: 39961525f504962d9345cb6e9ab6215c624717d710db5e801b6fad872a8b60dc792233f66f653711c17aa694aa961263d720a8c75084e54d6832c55315c57f65
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
- mix(attrs, Forms::TagField.root_tag_attributes(name: field_name(tag[:name]), id: field_id(tag[:name])))
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
@@ -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, but emits the ROOT's `data-reactive-tags-field` raw rather than via
22
- # reactive_tags(:tags): that helper compiles a SYMBOL through the class-level
23
- # reactive_scope, but a form builder's wire name is per-instance ("user[tags]").
24
- # The data attribute IS the public contract; any CSS selector works (issue #6
25
- # Caveats 1 & 2). Likewise the query input targets by #id so it never submits.
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 root's tag wire attrs. Raw, not reactive_tags(:tags)/reactive_filter(:q)
52
- # (Caveats 1 & 2): target the hidden field by [name=…] and the query input by
53
- # #id (an id selector means the query input never submits a stray param).
54
- # Public so Forms::Live can hoist these onto the <form> root when the widget
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
- def root_tag_attributes = self.class.root_tag_attributes(name: @name, id: @id)
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: "#{@id}_query", type: "search", autocomplete: "off",
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PhlexForms
4
- VERSION = "0.2.6"
4
+ VERSION = "0.2.7"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phlex-forms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikael Henriksson