diff --git a/src/cljs/auto_ap/forms.cljs b/src/cljs/auto_ap/forms.cljs index ebe989ac..798f8c63 100644 --- a/src/cljs/auto_ap/forms.cljs +++ b/src/cljs/auto_ap/forms.cljs @@ -107,11 +107,18 @@ ] 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] (let [{:keys [data]} @(re-frame/subscribe [::form id])] [:div.field (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 [] (when-let [error (:error @(re-frame/subscribe [::form id]))] diff --git a/src/cljs/auto_ap/views/components/typeahead.cljs b/src/cljs/auto_ap/views/components/typeahead.cljs index ee6c6500..929826c6 100644 --- a/src/cljs/auto_ap/views/components/typeahead.cljs +++ b/src/cljs/auto_ap/views/components/typeahead.cljs @@ -47,7 +47,8 @@ [:div.tags.has-addons [:span.tag text] [:a.tag.is-delete {:on-click (fn [] (select [nil "" nil]))}]]]] - ^{:key "typeahead"} [:input.input {:type "text" + ^{:key "typeahead"} + [:input.input {:type "text" :class class :value text @@ -152,7 +153,10 @@ [:div.control [:div.tags.has-addons [: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" :class class @@ -172,6 +176,7 @@ :else (do (select nil) + (reset! highlighted nil) (reset! text-atom nil) true))) :on-key-down (fn [e] diff --git a/src/cljs/auto_ap/views/pages/transactions/form.cljs b/src/cljs/auto_ap/views/pages/transactions/form.cljs index b18e2cdb..c3d9e114 100644 --- a/src/cljs/auto_ap/views/pages/transactions/form.cljs +++ b/src/cljs/auto_ap/views/pages/transactions/form.cljs @@ -54,11 +54,13 @@ (update :accounts expense-accounts-field/from-graphql (:amount which) locations)))))) (re-frame/reg-event-fx - ::change-vendor + ::changed [(forms/in-form ::form)] (fn [{{:keys [data]} :db} [_ field value]] (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 field value [:accounts] (expense-accounts-field/default-account (:accounts data) @@ -107,8 +109,8 @@ ;; VIEWS -(def my-form (forms/vertical-form {:can-submit [::can-submit] - :change-event [::forms/change ::form] +(def transaction-form (forms/vertical-form {:can-submit [::can-submit] + :change-event [::changed] :submit-event [::saving ] :id ::form})) @@ -137,7 +139,7 @@ (let [change-event [::forms/change ::form] {:keys [data] } @(re-frame/subscribe [::forms/form ::form]) 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} [field "Merchant" [:input.input {:type "text" @@ -164,8 +166,7 @@ :type "typeahead-entity" :auto-focus true :field [:vendor] - :disabled (boolean (:payment data)) - :event [::change-vendor]}]] + :disabled (boolean (:payment data))}]] [field nil [expense-accounts-field {:type "expense-accounts" @@ -173,7 +174,16 @@ :max (Math/abs (js/parseFloat (:amount data))) :descriptor "credit account" :disabled (boolean (:payment data)) - :locations locations - :event change-event}]] + :locations locations}]] + + + [:div.field + [:label.checkbox + [raw-field + [:input + {:type "checkbox" + :field [:exclude-from-ledger]}]] + " Exclude from ledger"]] + [error-notification] [submit-button "Save"]])])])