RE: Empty Form Fields
I have a multi-page app. The frontend has a form html element with two fields (no js). The fields are number and name
I have clojure spec specified for the form fields and router form
(s/def ::number int?)
(s/def ::name string?)
;; the route looks like this
:parameters {:form (s/keys :opt-un [::number] :req-un [::name])}
The above will fail when posted to because number is "" (that’s just what the browser does when submitting empty inputs). Is it possible to have reitit ignore empty strings for posts? Curious how people are handling this scenario.
One approach is say that the field can be an empty string and then I process it later:
(s/def ::number (s/or :empty-string string/blank? :number int?))Hi, coercion with a custom transformer is the another and more centrally handled way to achieve this. http://cljdoc.org/d/metosin/reitit/0.8.0-alpha1/doc/coercion/clojure-spec
Thanks! I'll look into this. I figured it was likely there was a way to do this.