From 54dbfcfbe0d0fc213f3556ea34269a157dc18a9d Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Wed, 21 Dec 2022 11:16:42 -0800 Subject: [PATCH] tries to allow percentages. --- .../auto_ap/views/components/percentage_field.cljs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cljs/auto_ap/views/components/percentage_field.cljs b/src/cljs/auto_ap/views/components/percentage_field.cljs index 7ff18035..3191ebfa 100644 --- a/src/cljs/auto_ap/views/components/percentage_field.cljs +++ b/src/cljs/auto_ap/views/components/percentage_field.cljs @@ -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"