diff --git a/project.clj b/project.clj index d64a59e..505d683 100644 --- a/project.clj +++ b/project.clj @@ -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"} diff --git a/src/formulare/core.clj b/src/formulare/core.clj index a55175e..63cd250 100644 --- a/src/formulare/core.clj +++ b/src/formulare/core.clj @@ -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)) diff --git a/test/formulare/core_test.clj b/test/formulare/core_test.clj index de04f10..ce6f604 100644 --- a/test/formulare/core_test.clj +++ b/test/formulare/core_test.clj @@ -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 "