diff --git a/project.clj b/project.clj index 505d683..50e09bc 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject joshavg/formulare "0.3.2-SNAPSHOT" +(defproject joshavg/formulare "0.3.3-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 63cd250..d500748 100644 --- a/src/formulare/core.clj +++ b/src/formulare/core.clj @@ -54,11 +54,11 @@ true (:form-specs form-def))) -(defn field-specs-valid? [form-def data] +(defn field-specs-valid? [form-def req] (reduce-kv (fn [result field field-def] (if-let [field-spec (:spec field-def)] - (if (spec/valid? field-spec (field data)) + (if (spec/valid? field-spec (get-in req [:params field])) true (reduced false)) result)) @@ -68,7 +68,7 @@ (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) + (and (field-specs-valid? form-def req) (form-specs-valid? form-def req)))) (def ^:dynamic *row-theme* theme/row) @@ -93,7 +93,9 @@ :mselect *mselect-widget-theme* :hidden *hidden-widget-theme* *input-widget-theme*)] - (*row-theme* (when (and validate? (not (spec/valid? spec req-value))) + (*row-theme* (when (and validate? + spec + (not (spec/valid? spec req-value))) (*widget-error-theme* id def req-value)) (*label-theme* id def) (renderer id def (if validate? req-value value))))) diff --git a/test/formulare/core_test.clj b/test/formulare/core_test.clj index ce6f604..07c17ee 100644 --- a/test/formulare/core_test.clj +++ b/test/formulare/core_test.clj @@ -51,9 +51,9 @@ :spec nil? :required false}}}] (is (= true (valid? def {:params {:name nil}}))))) - (testing "converted values are passed to spec" + (testing "unconverted values are passed to spec" (let [def {:fields {:foo {:label "" - :spec number? + :spec string? :from-req bigint} :bar {:label "" :spec string?}}}]