Minor tweaks for percentages
This commit is contained in:
@@ -15,50 +15,32 @@
|
||||
|
||||
:else
|
||||
(str (js/parseFloat value)))})]
|
||||
(react/useEffect (fn []
|
||||
;; allow the controlling field to change the raw representation
|
||||
;; when the raw amount is a valid representation, so that 33.
|
||||
;; doesn't get unset
|
||||
(when (or
|
||||
(and (:raw parsed-amount)
|
||||
(re-find good-% (:raw parsed-amount)))
|
||||
(str/blank? (:raw parsed-amount)))
|
||||
(set-parsed-amount
|
||||
(assoc parsed-amount
|
||||
:parsed value
|
||||
:raw (cond
|
||||
(str/blank? value)
|
||||
""
|
||||
|
||||
(js/Number.isNaN (js/parseFloat value))
|
||||
""
|
||||
|
||||
:else
|
||||
(str (js/parseFloat value))))))
|
||||
nil))
|
||||
[:div.control.has-icons-left
|
||||
[:input.input {:type "text"
|
||||
:disabled disabled
|
||||
:placeholder placeholder
|
||||
:class class
|
||||
:on-change (fn [e]
|
||||
(let [raw (.. e -target -value)
|
||||
new-value (when (and raw
|
||||
(not (str/blank? raw))
|
||||
(re-find good-% raw))
|
||||
(js/parseFloat raw))]
|
||||
(set-parsed-amount {:raw raw
|
||||
:parsed new-value})
|
||||
(when (not= value new-value)
|
||||
(on-change new-value))))
|
||||
(set-parsed-amount
|
||||
(assoc parsed-amount :raw (.. e -target -value))))
|
||||
:value (or (:raw parsed-amount)
|
||||
"")
|
||||
:on-blur (fn []
|
||||
(when-not (re-find good-% (:raw parsed-amount))
|
||||
|
||||
(set-parsed-amount {:raw ""
|
||||
:parsed nil})
|
||||
(on-change nil))
|
||||
(let [raw (:raw parsed-amount)]
|
||||
(if (re-find good-% raw)
|
||||
(let [new-value (when (and raw
|
||||
(not (str/blank? raw))
|
||||
(re-find good-% raw))
|
||||
(js/parseFloat raw))]
|
||||
(set-parsed-amount {:raw raw
|
||||
:parsed new-value})
|
||||
(when (not= value new-value)
|
||||
(on-change new-value)))
|
||||
|
||||
(do
|
||||
(set-parsed-amount {:raw ""
|
||||
:parsed nil})
|
||||
(on-change nil))))
|
||||
(when on-blur
|
||||
(on-blur)))
|
||||
:min min
|
||||
|
||||
@@ -104,15 +104,22 @@
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::updated
|
||||
[(re-frame/inject-cofx ::inject/sub [::subs/client])]
|
||||
(fn [{:keys [db] ::subs/keys [client]} [_ _ command]]
|
||||
[
|
||||
(re-frame/inject-cofx ::inject/sub (fn [[_ _ _ client]]
|
||||
[::subs/locations-for-client (:id client)]))]
|
||||
(fn [{:keys [db] ::subs/keys [locations-for-client]} [_ _ command client]]
|
||||
(println locations-for-client)
|
||||
(when (= :create command)
|
||||
{:db
|
||||
(-> db
|
||||
(forms/stop-form ::form )
|
||||
(forms/start-form ::form {:client client
|
||||
:status :unpaid
|
||||
:date (c/now)}))})))
|
||||
:date (c/now)
|
||||
:expense-accounts
|
||||
(eaf/from-graphql []
|
||||
0.0
|
||||
locations-for-client)}))})))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::adding
|
||||
@@ -253,7 +260,8 @@
|
||||
:class "live-added")
|
||||
(if (:id data)
|
||||
:edit
|
||||
:create)])
|
||||
:create)
|
||||
(:client data)])
|
||||
:on-error [::forms/save-error ::form]}})))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
|
||||
Reference in New Issue
Block a user