pass the bare req to form-specs

master
Josha von Gizycki 6 years ago
parent f4783d1fb4
commit 53d95a5ea7

@ -1,4 +1,4 @@
(defproject joshavg/formulare "0.3.1-SNAPSHOT"
(defproject joshavg/formulare "0.3.2-SNAPSHOT"
:description "Forms hiccup style"
:url "https://gitea.heevyis.ninja/josha/formulare.git"
:scm {:name "git" :url "https://gitea.heevyis.ninja/josha/formulare.git"}

@ -46,9 +46,9 @@
{}
(:fields form-def)))
(defn form-specs-valid? [form-def data]
(reduce (fn [valid? field-spec]
(if (spec/valid? field-spec data)
(defn form-specs-valid? [form-def req]
(reduce (fn [valid? form-spec]
(if (spec/valid? form-spec req)
true
(reduced false)))
true
@ -69,7 +69,7 @@
{: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))))
(form-specs-valid? form-def req))))
(def ^:dynamic *row-theme* theme/row)
(def ^:dynamic *widget-error-theme* theme/widget-error)
@ -111,7 +111,8 @@
(spec/explain-data ::form form-def))))
(let [validate? (validate? form-def values req)
form-errors (when (and validate?
(not (form-specs-valid? form-def req)))
(not (form-specs-valid? form-def
req)))
(*form-error-theme* form-def req))
widget-mapper (partial widget-markup values req validate?)
defined-widgets (map widget-mapper (:fields form-def))

@ -262,7 +262,7 @@
(deftest form-specs-is-applied
(testing "valid spec"
(let [def {:fields {}
:form-specs [(fn [vals] true)]}]
:form-specs [(fn [req] true)]}]
(is (= [:input {:type "hidden"
:name "__form-hash"
:id "__form-hash"
@ -274,7 +274,7 @@
{:params {:__form-hash (form-hash def {})}}))))))
(testing "invalid spec"
(let [def {:fields {}
:form-specs [(fn [vals] false)]}]
:form-specs [(fn [req] false)]}]
(is (= [:section.flash--error
[:h2.flash__heading--error "Warning"]
[:p "The form must comply to "

Loading…
Cancel
Save