mirror of
https://github.com/penpot/penpot.git
synced 2025-02-10 09:08:31 -05:00
Merge pull request #279 from uxbox/trimming-input
✨ Trim spaces in profile input fields
This commit is contained in:
commit
21b074c547
4 changed files with 15 additions and 9 deletions
|
@ -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
|
||||
|
|
|
@ -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")}]]])
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Add table
Reference in a new issue