mirror of
https://github.com/penpot/penpot.git
synced 2025-02-16 03:58:20 -05:00
✨ Trim spaces in profile input fields
This commit is contained in:
parent
e3e148c569
commit
92388df7f8
4 changed files with 15 additions and 9 deletions
|
@ -22,7 +22,7 @@
|
||||||
(def form-ctx (mf/create-context nil))
|
(def form-ctx (mf/create-context nil))
|
||||||
|
|
||||||
(mf/defc input
|
(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)
|
(let [form (mf/use-ctx form-ctx)
|
||||||
|
|
||||||
type' (mf/use-state type)
|
type' (mf/use-state type)
|
||||||
|
@ -62,7 +62,7 @@
|
||||||
"password"))))
|
"password"))))
|
||||||
|
|
||||||
on-focus #(reset! focus? true)
|
on-focus #(reset! focus? true)
|
||||||
on-change (fm/on-input-change form name)
|
on-change (fm/on-input-change form name trim)
|
||||||
|
|
||||||
on-blur
|
on-blur
|
||||||
(fn [event]
|
(fn [event]
|
||||||
|
@ -71,7 +71,7 @@
|
||||||
(swap! form assoc-in [:touched name] true)))
|
(swap! form assoc-in [:touched name] true)))
|
||||||
|
|
||||||
props (-> props
|
props (-> props
|
||||||
(dissoc :help-icon :form)
|
(dissoc :help-icon :form :trim)
|
||||||
(assoc :value value
|
(assoc :value value
|
||||||
:on-focus on-focus
|
:on-focus on-focus
|
||||||
:on-blur on-blur
|
:on-blur on-blur
|
||||||
|
|
|
@ -72,11 +72,13 @@
|
||||||
:initial {}}
|
:initial {}}
|
||||||
[:& input {:type "text"
|
[:& input {:type "text"
|
||||||
:name :email-1
|
:name :email-1
|
||||||
:label (t locale "settings.new-email-label")}]
|
:label (t locale "settings.new-email-label")
|
||||||
|
:trim true}]
|
||||||
|
|
||||||
[:& input {:type "text"
|
[:& input {:type "text"
|
||||||
:name :email-2
|
:name :email-2
|
||||||
:label (t locale "settings.confirm-email-label")}]
|
:label (t locale "settings.confirm-email-label")
|
||||||
|
:trim true}]
|
||||||
|
|
||||||
[:& submit-button
|
[:& submit-button
|
||||||
{:label (t locale "settings.change-email-submit-label")}]]])
|
{:label (t locale "settings.change-email-submit-label")}]]])
|
||||||
|
|
|
@ -58,7 +58,8 @@
|
||||||
[:& input
|
[:& input
|
||||||
{:type "text"
|
{:type "text"
|
||||||
:name :fullname
|
:name :fullname
|
||||||
:label (t locale "settings.fullname-label")}]
|
:label (t locale "settings.fullname-label")
|
||||||
|
:trim true}]
|
||||||
|
|
||||||
[:& input
|
[:& input
|
||||||
{:type "email"
|
{:type "email"
|
||||||
|
|
|
@ -74,14 +74,17 @@
|
||||||
(impl-mutator update-state))))
|
(impl-mutator update-state))))
|
||||||
|
|
||||||
(defn on-input-change
|
(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]
|
(fn [event]
|
||||||
(let [target (dom/get-target event)
|
(let [target (dom/get-target event)
|
||||||
value (dom/get-value target)]
|
value (dom/get-value target)]
|
||||||
(swap! form (fn [state]
|
(swap! form (fn [state]
|
||||||
(-> state
|
(-> state
|
||||||
(assoc-in [:data field] value)
|
(assoc-in [:data field] (if trim? (str/trim value) value))
|
||||||
(update :errors dissoc field)))))))
|
(update :errors dissoc field))))))))
|
||||||
|
|
||||||
(defn on-input-blur
|
(defn on-input-blur
|
||||||
[{:keys [touched] :as form} field]
|
[{:keys [touched] :as form} field]
|
||||||
|
|
Loading…
Add table
Reference in a new issue