try using clojure spec for validation

This commit is contained in:
Adrian Tiberius 2016-06-22 11:18:46 +03:00
parent b5ea433420
commit 42d8ea47df
3 changed files with 15 additions and 6 deletions

View File

@ -3,8 +3,8 @@
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.7.0"]
[org.clojure/clojurescript "1.7.170"]
:dependencies [[org.clojure/clojure "1.9.0-alpha7"]
[org.clojure/clojurescript "1.9.76"]
[reagent "0.5.1" :exclusions [cljsjs/react]]
[re-frame "0.6.0"]
[prismatic/schema "1.0.4"]

View File

@ -0,0 +1,10 @@
(ns status-im.contacts.validations
(:require [cljs.spec :as s]))
(s/def ::not-empty-string (s/and string? not-empty))
(s/def ::name ::not-empty-string)
(s/def ::whisper-identity ::not-empty-string)
(s/def ::contact (s/keys :req-un [::name ::whisper-identity]
:opt-un [::phone ::photo-path ::address]))

View File

@ -23,6 +23,8 @@
form-text-input]]
[status-im.qr-scanner.views.scan-button :refer [scan-button]]
[status-im.i18n :refer [label]]
[cljs.spec :as s]
[status-im.contacts.validations :as v]
[status-im.contacts.styles :as st]))
@ -32,9 +34,6 @@
[text {:style toolbar-title-text}
(label :t/add-new-contact)]])
(defn valid-form? [name address]
(and (not (str/blank? name)) (not (str/blank? address))))
(defview contact-name-input [name]
[]
[text-input
@ -67,7 +66,7 @@
:style icon-back}
:handler #(dispatch [:navigate-back])}
:custom-content toolbar-title
:action {:image {:source {:uri (if (valid-form? name whisper-identity)
:action {:image {:source {:uri (if (s/valid? ::v/contact new-contact)
:icon_ok_blue
:icon_ok_disabled)}
:style icon-search}