From 92388df7f8ca2b428c641e6bb6565505e65f9aef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Mon, 20 Jul 2020 12:23:09 +0200 Subject: [PATCH] :sparkles: Trim spaces in profile input fields --- frontend/src/uxbox/main/ui/components/forms.cljs | 6 +++--- frontend/src/uxbox/main/ui/settings/change_email.cljs | 6 ++++-- frontend/src/uxbox/main/ui/settings/profile.cljs | 3 ++- frontend/src/uxbox/util/forms.cljs | 9 ++++++--- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/frontend/src/uxbox/main/ui/components/forms.cljs b/frontend/src/uxbox/main/ui/components/forms.cljs index 47367c10f..81a0e43b5 100644 --- a/frontend/src/uxbox/main/ui/components/forms.cljs +++ b/frontend/src/uxbox/main/ui/components/forms.cljs @@ -22,7 +22,7 @@ (def form-ctx (mf/create-context nil)) (mf/defc input - [{:keys [type label help-icon disabled name form hint] :as props}] + [{:keys [type label help-icon disabled name form hint trim] :as props}] (let [form (mf/use-ctx form-ctx) type' (mf/use-state type) @@ -62,7 +62,7 @@ "password")))) on-focus #(reset! focus? true) - on-change (fm/on-input-change form name) + on-change (fm/on-input-change form name trim) on-blur (fn [event] @@ -71,7 +71,7 @@ (swap! form assoc-in [:touched name] true))) props (-> props - (dissoc :help-icon :form) + (dissoc :help-icon :form :trim) (assoc :value value :on-focus on-focus :on-blur on-blur diff --git a/frontend/src/uxbox/main/ui/settings/change_email.cljs b/frontend/src/uxbox/main/ui/settings/change_email.cljs index 95214b85f..67c8887a7 100644 --- a/frontend/src/uxbox/main/ui/settings/change_email.cljs +++ b/frontend/src/uxbox/main/ui/settings/change_email.cljs @@ -72,11 +72,13 @@ :initial {}} [:& input {:type "text" :name :email-1 - :label (t locale "settings.new-email-label")}] + :label (t locale "settings.new-email-label") + :trim true}] [:& input {:type "text" :name :email-2 - :label (t locale "settings.confirm-email-label")}] + :label (t locale "settings.confirm-email-label") + :trim true}] [:& submit-button {:label (t locale "settings.change-email-submit-label")}]]]) diff --git a/frontend/src/uxbox/main/ui/settings/profile.cljs b/frontend/src/uxbox/main/ui/settings/profile.cljs index 3bc4349c2..c3d2c6456 100644 --- a/frontend/src/uxbox/main/ui/settings/profile.cljs +++ b/frontend/src/uxbox/main/ui/settings/profile.cljs @@ -58,7 +58,8 @@ [:& input {:type "text" :name :fullname - :label (t locale "settings.fullname-label")}] + :label (t locale "settings.fullname-label") + :trim true}] [:& input {:type "email" diff --git a/frontend/src/uxbox/util/forms.cljs b/frontend/src/uxbox/util/forms.cljs index d5de8b602..6d819b3e6 100644 --- a/frontend/src/uxbox/util/forms.cljs +++ b/frontend/src/uxbox/util/forms.cljs @@ -74,14 +74,17 @@ (impl-mutator update-state)))) (defn on-input-change - [{:keys [data] :as form} field] + ([{:keys [data] :as form} field] + (on-input-change form field false)) + + ([{:keys [data] :as form} field trim?] (fn [event] (let [target (dom/get-target event) value (dom/get-value target)] (swap! form (fn [state] (-> state - (assoc-in [:data field] value) - (update :errors dissoc field))))))) + (assoc-in [:data field] (if trim? (str/trim value) value)) + (update :errors dissoc field)))))))) (defn on-input-blur [{:keys [touched] :as form} field]