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" :description "Forms hiccup style"
:url "https://gitea.heevyis.ninja/josha/formulare.git" :url "https://gitea.heevyis.ninja/josha/formulare.git"
:scm {:name "git" :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))) (:fields form-def)))
(defn form-specs-valid? [form-def data] (defn form-specs-valid? [form-def req]
(reduce (fn [valid? field-spec] (reduce (fn [valid? form-spec]
(if (spec/valid? field-spec data) (if (spec/valid? form-spec req)
true true
(reduced false))) (reduced false)))
true true
@ -69,7 +69,7 @@
{:pre [(spec/assert ::form form-def)]} {:pre [(spec/assert ::form form-def)]}
(let [data (form-data form-def req)] (let [data (form-data form-def req)]
(and (field-specs-valid? form-def data) (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 *row-theme* theme/row)
(def ^:dynamic *widget-error-theme* theme/widget-error) (def ^:dynamic *widget-error-theme* theme/widget-error)
@ -111,7 +111,8 @@
(spec/explain-data ::form form-def)))) (spec/explain-data ::form form-def))))
(let [validate? (validate? form-def values req) (let [validate? (validate? form-def values req)
form-errors (when (and validate? 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)) (*form-error-theme* form-def req))
widget-mapper (partial widget-markup values req validate?) widget-mapper (partial widget-markup values req validate?)
defined-widgets (map widget-mapper (:fields form-def)) defined-widgets (map widget-mapper (:fields form-def))

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

Loading…
Cancel
Save