fix(ssr): allow picking bank account when editing a transaction rule

The bank-account filter rendered "Please select a client" even when a
client was set on the rule. Two causes:

- Inside (fc/with-field :transaction-rule/bank-account ...) the cursor is
  rebound to the bank-account field, so (:transaction-rule/client
  (fc/field-value)) read the nil bank-account value and the server
  rendered the placeholder. The clientId watcher only fires on change, so
  when editing (client preset, unchanged) the htmx swap never corrected
  it. Read the client from the form root before entering the field.
- The clientId-change swap used innerHTML, nesting a fresh typeahead
  inside the stale one and breaking its Alpine refs. Use outerHTML so the
  typeahead is replaced in place.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-17 13:32:30 -07:00
parent 6b4392b74b
commit d0028f403c

View File

@@ -722,25 +722,26 @@
:class "w-24" :class "w-24"
:placeholder "NTG" :placeholder "NTG"
:value (fc/field-value)})])) :value (fc/field-value)})]))
(fc/with-field :transaction-rule/bank-account (let [rule-client (fc/field-value (:transaction-rule/client fc/*current*))]
(com/validated-field (fc/with-field :transaction-rule/bank-account
(-> {:label "Bank Account" (com/validated-field
:errors (fc/field-errors) (-> {:label "Bank Account"
:x-show "bankAccountFilter"} :errors (fc/field-errors)
hx/alpine-appear) :x-show "bankAccountFilter"}
[:div.w-96 hx/alpine-appear)
[:div#bank-account-changer {:hx-get (bidi/path-for ssr-routes/only-routes :bank-account-typeahead) [:div.w-96
:hx-trigger "changed" [:div#bank-account-changer {:hx-get (bidi/path-for ssr-routes/only-routes :bank-account-typeahead)
:hx-target "next *" :hx-trigger "changed"
:hx-include "#bank-account-changer" :hx-target "next *"
:hx-swap "innerHTML" :hx-include "#bank-account-changer"
:hx-swap "outerHTML"
:hx-vals (format "js:{name: '%s', 'client-id': event.detail.clientId}" (fc/field-name)) :hx-vals (format "js:{name: '%s', 'client-id': event.detail.clientId}" (fc/field-name))
:x-init "$watch('clientId', cid => $dispatch('changed', $data))"}] :x-init "$watch('clientId', cid => $dispatch('changed', $data))"}]
(bank-account-typeahead* {:client-id (:transaction-rule/client (fc/field-value)) (bank-account-typeahead* {:client-id (or (:db/id rule-client) rule-client)
:name (fc/field-name) :name (fc/field-name)
:value (fc/field-value)})])) :value (fc/field-value)})])))
(com/field (-> {:label "Amount" (com/field (-> {:label "Amount"
:x-show "amountFilter"} :x-show "amountFilter"}