Validate even on submit press
This commit is contained in:
parent
acd05e2687
commit
2a292e96e5
|
@ -2,6 +2,7 @@
|
||||||
(:require status-im.utils.db
|
(:require status-im.utils.db
|
||||||
status-im.ui.screens.network-settings.db
|
status-im.ui.screens.network-settings.db
|
||||||
status-im.ui.screens.bootnodes-settings.db
|
status-im.ui.screens.bootnodes-settings.db
|
||||||
|
[clojure.string :as string]
|
||||||
[cljs.spec.alpha :as spec]
|
[cljs.spec.alpha :as spec]
|
||||||
[status-im.constants :as const])
|
[status-im.constants :as const])
|
||||||
(:require-macros [status-im.utils.db :refer [allowed-keys]]))
|
(:require-macros [status-im.utils.db :refer [allowed-keys]]))
|
||||||
|
@ -16,6 +17,11 @@
|
||||||
(defn valid-length? [password]
|
(defn valid-length? [password]
|
||||||
(>= (count password) const/min-password-length))
|
(>= (count password) const/min-password-length))
|
||||||
|
|
||||||
|
(defn account-creation-next-enabled? [{:keys [step password password-confirm name]}]
|
||||||
|
(or (and password (= :enter-password step) (spec/valid? ::password password))
|
||||||
|
(and password-confirm (= :confirm-password step) (spec/valid? ::password password-confirm))
|
||||||
|
(and name (= :enter-name step) (not (string/blank? name)))))
|
||||||
|
|
||||||
(spec/def ::password (spec/and :global/not-empty-string valid-length?))
|
(spec/def ::password (spec/and :global/not-empty-string valid-length?))
|
||||||
|
|
||||||
(spec/def :account/address :global/address)
|
(spec/def :account/address :global/address)
|
||||||
|
|
|
@ -27,15 +27,15 @@
|
||||||
:input-placeholder (i18n/label :t/name-placeholder)
|
:input-placeholder (i18n/label :t/name-placeholder)
|
||||||
:input-description (i18n/label :t/name-description)}})
|
:input-description (i18n/label :t/name-description)}})
|
||||||
|
|
||||||
(defview input [{:keys [step error password password-confirm]}]
|
(defview input [next-enabled? {:keys [step error password password-confirm]}]
|
||||||
[text-input/text-input-with-label
|
[text-input/text-input-with-label
|
||||||
{:label (get-in steps [step :input-label])
|
(cond-> {:label (get-in steps [step :input-label])
|
||||||
:placeholder (get-in steps [step :input-placeholder])
|
:placeholder (get-in steps [step :input-placeholder])
|
||||||
:on-change-text #(re-frame/dispatch [:accounts.create.ui/input-text-changed (get-in steps [step :input-key]) %])
|
:on-change-text #(re-frame/dispatch [:accounts.create.ui/input-text-changed (get-in steps [step :input-key]) %])
|
||||||
:secure-text-entry (boolean (#{:enter-password :confirm-password} step))
|
:secure-text-entry (boolean (#{:enter-password :confirm-password} step))
|
||||||
:auto-focus true
|
:auto-focus true
|
||||||
:on-submit-editing #(re-frame/dispatch [:accounts.create.ui/next-step-pressed step password password-confirm])
|
:error error}
|
||||||
:error error}])
|
next-enabled? (assoc :on-submit-editing #(re-frame/dispatch [:accounts.create.ui/next-step-pressed step password password-confirm])))])
|
||||||
|
|
||||||
(defview create-account []
|
(defview create-account []
|
||||||
(letsubs [step [:get-in [:accounts/create :step]]
|
(letsubs [step [:get-in [:accounts/create :step]]
|
||||||
|
@ -63,10 +63,11 @@
|
||||||
[react/view components.styles/flex
|
[react/view components.styles/flex
|
||||||
[react/view {:style styles/input-container
|
[react/view {:style styles/input-container
|
||||||
:important-for-accessibility :no-hide-descendants}
|
:important-for-accessibility :no-hide-descendants}
|
||||||
[input {:step step
|
[input next-enabled?
|
||||||
:error error
|
{:step step
|
||||||
:password password
|
:error error
|
||||||
:password-confirm password-confirm}]
|
:password password
|
||||||
|
:password-confirm password-confirm}]
|
||||||
[react/text {:style styles/input-description}
|
[react/text {:style styles/input-description}
|
||||||
(get-in steps [step :input-description])]]
|
(get-in steps [step :input-description])]]
|
||||||
[react/view {:style components.styles/flex}]
|
[react/view {:style components.styles/flex}]
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
(ns status-im.ui.screens.accounts.subs
|
(ns status-im.ui.screens.accounts.subs
|
||||||
(:require [re-frame.core :as re-frame]
|
(:require [re-frame.core :as re-frame]
|
||||||
[clojure.string :as string]
|
|
||||||
[status-im.accounts.db :as db]
|
[status-im.accounts.db :as db]
|
||||||
[status-im.utils.ethereum.core :as ethereum]
|
[status-im.utils.ethereum.core :as ethereum]
|
||||||
[cljs.spec.alpha :as spec]))
|
[cljs.spec.alpha :as spec]))
|
||||||
|
@ -29,10 +28,7 @@
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
:get-account-creation-next-enabled?
|
:get-account-creation-next-enabled?
|
||||||
(fn [{:accounts/keys [create]}]
|
(fn [{:accounts/keys [create]}]
|
||||||
(let [{:keys [step password password-confirm name]} create]
|
(db/account-creation-next-enabled? create)))
|
||||||
(or (and password (= :enter-password step) (spec/valid? ::db/password password))
|
|
||||||
(and password-confirm (= :confirm-password step) (spec/valid? ::db/password password-confirm))
|
|
||||||
(and name (= :enter-name step) (not (string/blank? name)))))))
|
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
:get-recover-account
|
:get-recover-account
|
||||||
|
|
Loading…
Reference in New Issue