add money field.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
(:require [auto-ap.forms :as forms]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.views.components.typeahead :refer [typeahead typeahead-entity]]
|
||||
[auto-ap.views.components.money-field :refer [money-field]]
|
||||
[auto-ap.views.utils :refer [bind-field dispatch-event ->$]]
|
||||
[goog.string :as gstring]
|
||||
[re-frame.core :as re-frame]
|
||||
@@ -37,7 +38,7 @@
|
||||
|
||||
(update :amount js/parseFloat)
|
||||
(assoc :amount-percentage (* 100 (/ (js/parseFloat (:amount a))
|
||||
(Math/abs (js/parseFloat total)))))
|
||||
(Math/abs total))))
|
||||
(assoc :amount-mode "$")))
|
||||
accounts))
|
||||
[{:id (str "new-" (random-uuid))
|
||||
@@ -78,7 +79,7 @@
|
||||
(assoc ea :amount
|
||||
(js/parseFloat
|
||||
(goog.string/format "%.2f"
|
||||
(* (/ (js/parseFloat (:amount-percentage ea)) 100.0) (js/parseFloat total))))))
|
||||
(* (/ (js/parseFloat (:amount-percentage ea)) 100.0) total)))))
|
||||
expense-accounts))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
|
||||
23
src/cljs/auto_ap/views/components/money_field.cljs
Normal file
23
src/cljs/auto_ap/views/components/money_field.cljs
Normal file
@@ -0,0 +1,23 @@
|
||||
(ns auto-ap.views.components.money-field
|
||||
(:require [reagent.core :as r]
|
||||
[clojure.string :as str]))
|
||||
|
||||
(defn money-field [{:keys [min max disabled on-change value]}]
|
||||
(let [parsed-amount (r/atom {:parsed value
|
||||
:raw (str value)})]
|
||||
(fn [{:keys [min max disabled on-change value]}]
|
||||
[:input.input {:type "number"
|
||||
:disabled disabled
|
||||
:on-change (fn [e]
|
||||
(let [raw (.. e -target -value)
|
||||
new-value (when (and raw (not (str/blank? raw)))
|
||||
(js/parseFloat raw))]
|
||||
(swap! parsed-amount assoc
|
||||
:raw raw
|
||||
:parsed new-value)
|
||||
(when (not= value new-value)
|
||||
(on-change new-value))))
|
||||
:value (:raw @parsed-amount)
|
||||
:min min
|
||||
:max max
|
||||
:step "0.01"}])))
|
||||
Reference in New Issue
Block a user