supports validation and multiple account entering.
This commit is contained in:
@@ -29,10 +29,14 @@
|
||||
(re-frame/reg-event-fx
|
||||
::expense-account-changed
|
||||
(fn [_ [_ event expense-accounts field value]]
|
||||
{:dispatch (into event [(assoc-in expense-accounts field value)
|
||||
(if (= (list :account :id) (drop 1 field))
|
||||
(if-let [location (:location @(re-frame/subscribe [::subs/account value]))]
|
||||
[[(first field) :location] location]))])}))
|
||||
(let [updated-accounts (cond-> expense-accounts
|
||||
true (assoc-in field value)
|
||||
(= (list :account :id) (drop 1 field)) (assoc-in [(first field) :account] @(re-frame/subscribe [::subs/account value]))
|
||||
)
|
||||
updated-accounts (if-let [location (get-in updated-accounts [(first field) :account :location])]
|
||||
(assoc-in updated-accounts [(first field) :location] location)
|
||||
updated-accounts)]
|
||||
{:dispatch (into event [updated-accounts])})))
|
||||
|
||||
|
||||
;; VIEWS
|
||||
|
||||
@@ -17,17 +17,17 @@
|
||||
(let [text (r/atom (or (second (first (filter #(= (first %) value) matches))) ""))
|
||||
highlighted (r/atom nil)
|
||||
selected (r/atom (first (first (filter #(= (first %) value) matches))))
|
||||
select (fn [[id text-description text-value]]
|
||||
(reset! selected id)
|
||||
(reset! text text-description)
|
||||
(when on-change
|
||||
(if (= :not-found id)
|
||||
(on-change nil text-description text-value)
|
||||
(on-change id text-description (or text-value text-description)))))]
|
||||
]
|
||||
(r/create-class
|
||||
{:reagent-render (fn [{:keys [matches on-change disabled field text-field value class not-found-description]}]
|
||||
|
||||
(let [text @text
|
||||
(let [ select (fn [[id text-description text-value]]
|
||||
(reset! selected id)
|
||||
(reset! text text-description)
|
||||
(when on-change
|
||||
(if (= :not-found id)
|
||||
(on-change nil text-description text-value)
|
||||
(on-change id text-description (or text-value text-description)))))
|
||||
text @text
|
||||
valid-matches (get-valid-matches matches not-found-description not-found-value text)]
|
||||
[:div.typeahead
|
||||
(if disabled
|
||||
|
||||
Reference in New Issue
Block a user