A way better approach for form validation. Feels good now.
This commit is contained in:
19
src/cljs/auto_ap/schema.cljs
Normal file
19
src/cljs/auto_ap/schema.cljs
Normal file
@@ -0,0 +1,19 @@
|
||||
(ns auto-ap.schema
|
||||
(:require [malli.core :as m]))
|
||||
|
||||
(def reference (m/schema [:map [:id :string]]))
|
||||
(def date (m/schema [:fn
|
||||
(fn [d]
|
||||
(if-not (or (instance? goog.date.DateTime d)
|
||||
(instance? goog.date.Date d))
|
||||
(throw (ex-info "Invalid Date" {:type ::m/invalid-type}))
|
||||
true))]))
|
||||
|
||||
(def money (m/schema [float? {:error/message "Invalid money"}]))
|
||||
(def not-empty-string (m/schema [:re {:error/message "Required"} #"\S+"]))
|
||||
|
||||
(def expense-account (m/schema [:map
|
||||
[:id :string]
|
||||
[:account reference]
|
||||
[:location :string]
|
||||
[:amount money]]))
|
||||
Reference in New Issue
Block a user