|
|
@ -33,19 +33,43 @@
|
|
|
|
(spec/keys :req-un [::fields]
|
|
|
|
(spec/keys :req-un [::fields]
|
|
|
|
:opt-un [::form-specs]))
|
|
|
|
:opt-un [::form-specs]))
|
|
|
|
|
|
|
|
|
|
|
|
(defn valid? [form-def req]
|
|
|
|
(defn form-data [form-def req]
|
|
|
|
{:pre [(spec/assert ::form form-def)]}
|
|
|
|
(when-not (spec/valid? ::form form-def)
|
|
|
|
(reduce-kv
|
|
|
|
(throw (ex-info "Form def fails spec" (spec/explain-data ::form form-def))))
|
|
|
|
(fn [result field value]
|
|
|
|
(reduce (fn [coll [id field]]
|
|
|
|
(if-let [field-spec (get-in form-def [:fields field :spec])]
|
|
|
|
(let [value (get-in req [:params id])]
|
|
|
|
(let [from-req (get-in form-def [:fields field :from-req])
|
|
|
|
(assoc coll
|
|
|
|
check-value (if from-req (from-req value) value)]
|
|
|
|
id
|
|
|
|
(if (spec/valid? field-spec check-value)
|
|
|
|
(if-let [from-req (:from-req field)]
|
|
|
|
|
|
|
|
(from-req value)
|
|
|
|
|
|
|
|
value))))
|
|
|
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
(:fields form-def)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defn form-specs-valid? [form-def data]
|
|
|
|
|
|
|
|
(reduce (fn [valid? field-spec]
|
|
|
|
|
|
|
|
(if (spec/valid? field-spec data)
|
|
|
|
true
|
|
|
|
true
|
|
|
|
(reduced false)))
|
|
|
|
(reduced false)))
|
|
|
|
|
|
|
|
true
|
|
|
|
|
|
|
|
(:form-specs form-def)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defn field-specs-valid? [form-def data]
|
|
|
|
|
|
|
|
(reduce-kv
|
|
|
|
|
|
|
|
(fn [result field field-def]
|
|
|
|
|
|
|
|
(if-let [field-spec (:spec field-def)]
|
|
|
|
|
|
|
|
(if (spec/valid? field-spec (field data))
|
|
|
|
|
|
|
|
true
|
|
|
|
|
|
|
|
(reduced false))
|
|
|
|
result))
|
|
|
|
result))
|
|
|
|
true
|
|
|
|
true
|
|
|
|
(:params req)))
|
|
|
|
(:fields form-def)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defn valid? [form-def req]
|
|
|
|
|
|
|
|
{:pre [(spec/assert ::form form-def)]}
|
|
|
|
|
|
|
|
(let [data (form-data form-def req)]
|
|
|
|
|
|
|
|
(and (field-specs-valid? form-def data)
|
|
|
|
|
|
|
|
(form-specs-valid? form-def data))))
|
|
|
|
|
|
|
|
|
|
|
|
(def ^:dynamic *row-theme* theme/row)
|
|
|
|
(def ^:dynamic *row-theme* theme/row)
|
|
|
|
(def ^:dynamic *widget-error-theme* theme/widget-error)
|
|
|
|
(def ^:dynamic *widget-error-theme* theme/widget-error)
|
|
|
@ -74,14 +98,6 @@
|
|
|
|
(*label-theme* id def)
|
|
|
|
(*label-theme* id def)
|
|
|
|
(renderer id def (if validate? req-value value)))))
|
|
|
|
(renderer id def (if validate? req-value value)))))
|
|
|
|
|
|
|
|
|
|
|
|
(defn form-specs-valid? [form-def req]
|
|
|
|
|
|
|
|
(reduce (fn [valid? field-spec]
|
|
|
|
|
|
|
|
(if (spec/valid? field-spec (:params req))
|
|
|
|
|
|
|
|
true
|
|
|
|
|
|
|
|
(reduced false)))
|
|
|
|
|
|
|
|
true
|
|
|
|
|
|
|
|
(:form-specs form-def)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defn form-hash [form-def values]
|
|
|
|
(defn form-hash [form-def values]
|
|
|
|
(str (hash [form-def values])))
|
|
|
|
(str (hash [form-def values])))
|
|
|
|
|
|
|
|
|
|
|
@ -110,16 +126,3 @@
|
|
|
|
[form-errors])
|
|
|
|
[form-errors])
|
|
|
|
all-widgets)
|
|
|
|
all-widgets)
|
|
|
|
all-widgets)))
|
|
|
|
all-widgets)))
|
|
|
|
|
|
|
|
|
|
|
|
(defn form-data [form-def req]
|
|
|
|
|
|
|
|
(when-not (spec/valid? ::form form-def)
|
|
|
|
|
|
|
|
(throw (ex-info "Form def fails spec" (spec/explain-data ::form form-def))))
|
|
|
|
|
|
|
|
(reduce (fn [coll [id field]]
|
|
|
|
|
|
|
|
(let [value (get-in req [:params id])]
|
|
|
|
|
|
|
|
(assoc coll
|
|
|
|
|
|
|
|
id
|
|
|
|
|
|
|
|
(if-let [from-req (:from-req field)]
|
|
|
|
|
|
|
|
(from-req value)
|
|
|
|
|
|
|
|
value))))
|
|
|
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
(:fields form-def)))
|
|
|
|
|
|
|
|