tries to allow percentages.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
(:require [reagent.core :as r]
|
||||
[clojure.string :as str]
|
||||
[react :as react]))
|
||||
(def good-% #"^\d{1,3}$")
|
||||
(def good-% #"^\d{1,3}(?:\.\d{1,3})?$")
|
||||
|
||||
(defn -percentage-field [{:keys [min max disabled on-blur on-change value class style placeholder]}]
|
||||
(let [[ parsed-amount set-parsed-amount] (react/useState {:parsed value
|
||||
@@ -10,11 +10,11 @@
|
||||
(str/blank? value)
|
||||
""
|
||||
|
||||
(js/Number.isNaN (js/parseInt value))
|
||||
(js/Number.isNaN (js/parseFloat value))
|
||||
""
|
||||
|
||||
:else
|
||||
(str (js/parseInt value)))})]
|
||||
(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.
|
||||
@@ -30,11 +30,11 @@
|
||||
(str/blank? value)
|
||||
""
|
||||
|
||||
(js/Number.isNaN (js/parseInt value))
|
||||
(js/Number.isNaN (js/parseFloat value))
|
||||
""
|
||||
|
||||
:else
|
||||
(str (js/parseInt value))))))
|
||||
(str (js/parseFloat value))))))
|
||||
nil))
|
||||
[:div.control.has-icons-left
|
||||
[:input.input {:type "text"
|
||||
|
||||
Reference in New Issue
Block a user