single event for handling changes.
This commit is contained in:
@@ -107,11 +107,18 @@
|
|||||||
|
|
||||||
]
|
]
|
||||||
children)))
|
children)))
|
||||||
|
:raw-field (fn [control]
|
||||||
|
(let [{:keys [data]} @(re-frame/subscribe [::form id])]
|
||||||
|
[bind-field (-> control
|
||||||
|
(assoc-in [1 :subscription] data)
|
||||||
|
(assoc-in [1 :event] change-event))]))
|
||||||
:field (fn [label control]
|
:field (fn [label control]
|
||||||
(let [{:keys [data]} @(re-frame/subscribe [::form id])]
|
(let [{:keys [data]} @(re-frame/subscribe [::form id])]
|
||||||
[:div.field
|
[:div.field
|
||||||
(when label [:p.help label])
|
(when label [:p.help label])
|
||||||
[:div.control [bind-field (assoc-in control [1 :subscription] data)]]]))
|
[:div.control [bind-field (-> control
|
||||||
|
(assoc-in [1 :subscription] data)
|
||||||
|
(assoc-in [1 :event] change-event))]]]))
|
||||||
|
|
||||||
:error-notification (fn []
|
:error-notification (fn []
|
||||||
(when-let [error (:error @(re-frame/subscribe [::form id]))]
|
(when-let [error (:error @(re-frame/subscribe [::form id]))]
|
||||||
|
|||||||
@@ -47,7 +47,8 @@
|
|||||||
[:div.tags.has-addons
|
[:div.tags.has-addons
|
||||||
[:span.tag text]
|
[:span.tag text]
|
||||||
[:a.tag.is-delete {:on-click (fn [] (select [nil "" nil]))}]]]]
|
[:a.tag.is-delete {:on-click (fn [] (select [nil "" nil]))}]]]]
|
||||||
^{:key "typeahead"} [:input.input {:type "text"
|
^{:key "typeahead"}
|
||||||
|
[:input.input {:type "text"
|
||||||
:class class
|
:class class
|
||||||
|
|
||||||
:value text
|
:value text
|
||||||
@@ -152,7 +153,10 @@
|
|||||||
[:div.control
|
[:div.control
|
||||||
[:div.tags.has-addons
|
[:div.tags.has-addons
|
||||||
[:span.tag text]
|
[:span.tag text]
|
||||||
[:a.tag.is-delete {:on-click (fn [] (select nil) (reset! text-atom nil))}]]]]
|
[:a.tag.is-delete {:on-click (fn []
|
||||||
|
(select nil)
|
||||||
|
(reset! text-atom nil)
|
||||||
|
(reset! highlighted nil))}]]]]
|
||||||
^{:key "typeahead"} [:input.input {:type "text"
|
^{:key "typeahead"} [:input.input {:type "text"
|
||||||
:class class
|
:class class
|
||||||
|
|
||||||
@@ -172,6 +176,7 @@
|
|||||||
|
|
||||||
:else
|
:else
|
||||||
(do (select nil)
|
(do (select nil)
|
||||||
|
(reset! highlighted nil)
|
||||||
(reset! text-atom nil)
|
(reset! text-atom nil)
|
||||||
true)))
|
true)))
|
||||||
:on-key-down (fn [e]
|
:on-key-down (fn [e]
|
||||||
|
|||||||
@@ -54,11 +54,13 @@
|
|||||||
(update :accounts expense-accounts-field/from-graphql (:amount which) locations))))))
|
(update :accounts expense-accounts-field/from-graphql (:amount which) locations))))))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::change-vendor
|
::changed
|
||||||
[(forms/in-form ::form)]
|
[(forms/in-form ::form)]
|
||||||
(fn [{{:keys [data]} :db} [_ field value]]
|
(fn [{{:keys [data]} :db} [_ field value]]
|
||||||
(let [locations @(re-frame/subscribe [::subs/locations-for-client (:id (:client data))])]
|
(let [locations @(re-frame/subscribe [::subs/locations-for-client (:id (:client data))])]
|
||||||
(if (and value (expense-accounts-field/can-replace-with-default? (:accounts data)))
|
(if (and (= [:vendor] field)
|
||||||
|
value
|
||||||
|
(expense-accounts-field/can-replace-with-default? (:accounts data)))
|
||||||
{:dispatch [::forms/change ::form
|
{:dispatch [::forms/change ::form
|
||||||
field value
|
field value
|
||||||
[:accounts] (expense-accounts-field/default-account (:accounts data)
|
[:accounts] (expense-accounts-field/default-account (:accounts data)
|
||||||
@@ -107,8 +109,8 @@
|
|||||||
|
|
||||||
;; VIEWS
|
;; VIEWS
|
||||||
|
|
||||||
(def my-form (forms/vertical-form {:can-submit [::can-submit]
|
(def transaction-form (forms/vertical-form {:can-submit [::can-submit]
|
||||||
:change-event [::forms/change ::form]
|
:change-event [::changed]
|
||||||
:submit-event [::saving ]
|
:submit-event [::saving ]
|
||||||
:id ::form}))
|
:id ::form}))
|
||||||
|
|
||||||
@@ -137,7 +139,7 @@
|
|||||||
(let [change-event [::forms/change ::form]
|
(let [change-event [::forms/change ::form]
|
||||||
{:keys [data] } @(re-frame/subscribe [::forms/form ::form])
|
{:keys [data] } @(re-frame/subscribe [::forms/form ::form])
|
||||||
locations @(re-frame/subscribe [::subs/locations-for-client (:id (:client data))])
|
locations @(re-frame/subscribe [::subs/locations-for-client (:id (:client data))])
|
||||||
{:keys [form field error-notification submit-button ]} my-form]
|
{:keys [form field raw-field error-notification submit-button ]} transaction-form]
|
||||||
[form {:title "Hello" :edit-completed edit-completed}
|
[form {:title "Hello" :edit-completed edit-completed}
|
||||||
[field "Merchant"
|
[field "Merchant"
|
||||||
[:input.input {:type "text"
|
[:input.input {:type "text"
|
||||||
@@ -164,8 +166,7 @@
|
|||||||
:type "typeahead-entity"
|
:type "typeahead-entity"
|
||||||
:auto-focus true
|
:auto-focus true
|
||||||
:field [:vendor]
|
:field [:vendor]
|
||||||
:disabled (boolean (:payment data))
|
:disabled (boolean (:payment data))}]]
|
||||||
:event [::change-vendor]}]]
|
|
||||||
[field nil
|
[field nil
|
||||||
[expense-accounts-field
|
[expense-accounts-field
|
||||||
{:type "expense-accounts"
|
{:type "expense-accounts"
|
||||||
@@ -173,7 +174,16 @@
|
|||||||
:max (Math/abs (js/parseFloat (:amount data)))
|
:max (Math/abs (js/parseFloat (:amount data)))
|
||||||
:descriptor "credit account"
|
:descriptor "credit account"
|
||||||
:disabled (boolean (:payment data))
|
:disabled (boolean (:payment data))
|
||||||
:locations locations
|
:locations locations}]]
|
||||||
:event change-event}]]
|
|
||||||
|
|
||||||
|
[:div.field
|
||||||
|
[:label.checkbox
|
||||||
|
[raw-field
|
||||||
|
[:input
|
||||||
|
{:type "checkbox"
|
||||||
|
:field [:exclude-from-ledger]}]]
|
||||||
|
" Exclude from ledger"]]
|
||||||
|
|
||||||
[error-notification]
|
[error-notification]
|
||||||
[submit-button "Save"]])])])
|
[submit-button "Save"]])])])
|
||||||
|
|||||||
Reference in New Issue
Block a user