Validate even on submit press

This commit is contained in:
janherich 2018-10-17 10:56:54 +02:00
parent acd05e2687
commit 2a292e96e5
No known key found for this signature in database
GPG Key ID: C23B473AFBE94D13
3 changed files with 20 additions and 17 deletions

View File

@ -2,6 +2,7 @@
(:require status-im.utils.db
status-im.ui.screens.network-settings.db
status-im.ui.screens.bootnodes-settings.db
[clojure.string :as string]
[cljs.spec.alpha :as spec]
[status-im.constants :as const])
(:require-macros [status-im.utils.db :refer [allowed-keys]]))
@ -16,6 +17,11 @@
(defn valid-length? [password]
(>= (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 :account/address :global/address)

View File

@ -27,15 +27,15 @@
:input-placeholder (i18n/label :t/name-placeholder)
: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
{:label (get-in steps [step :input-label])
: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]) %])
:secure-text-entry (boolean (#{:enter-password :confirm-password} step))
:auto-focus true
:on-submit-editing #(re-frame/dispatch [:accounts.create.ui/next-step-pressed step password password-confirm])
:error error}])
(cond-> {:label (get-in steps [step :input-label])
: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]) %])
:secure-text-entry (boolean (#{:enter-password :confirm-password} step))
:auto-focus true
:error error}
next-enabled? (assoc :on-submit-editing #(re-frame/dispatch [:accounts.create.ui/next-step-pressed step password password-confirm])))])
(defview create-account []
(letsubs [step [:get-in [:accounts/create :step]]
@ -63,10 +63,11 @@
[react/view components.styles/flex
[react/view {:style styles/input-container
:important-for-accessibility :no-hide-descendants}
[input {:step step
:error error
:password password
:password-confirm password-confirm}]
[input next-enabled?
{:step step
:error error
:password password
:password-confirm password-confirm}]
[react/text {:style styles/input-description}
(get-in steps [step :input-description])]]
[react/view {:style components.styles/flex}]

View File

@ -1,6 +1,5 @@
(ns status-im.ui.screens.accounts.subs
(:require [re-frame.core :as re-frame]
[clojure.string :as string]
[status-im.accounts.db :as db]
[status-im.utils.ethereum.core :as ethereum]
[cljs.spec.alpha :as spec]))
@ -29,10 +28,7 @@
(re-frame/reg-sub
:get-account-creation-next-enabled?
(fn [{:accounts/keys [create]}]
(let [{:keys [step password password-confirm name]} 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)))))))
(db/account-creation-next-enabled? create)))
(re-frame/reg-sub
:get-recover-account