|
|
@ -82,71 +82,57 @@
|
|
|
|
true
|
|
|
|
true
|
|
|
|
(:params req)))
|
|
|
|
(:params req)))
|
|
|
|
|
|
|
|
|
|
|
|
(defn render-input [id {:keys [label required spec]} value req-value validate?]
|
|
|
|
(defn input-widget [id def value]
|
|
|
|
(list
|
|
|
|
(hform/text-field {:required (or (:required def) false)}
|
|
|
|
(when (and validate? (not (spec/valid? spec req-value)))
|
|
|
|
|
|
|
|
(spec-to-errmsg label spec req-value))
|
|
|
|
|
|
|
|
(hform/label id label)
|
|
|
|
|
|
|
|
(hform/text-field {:required (or required false)}
|
|
|
|
|
|
|
|
id
|
|
|
|
id
|
|
|
|
(if validate? req-value value))))
|
|
|
|
value))
|
|
|
|
|
|
|
|
|
|
|
|
(defn render-checkbox [id {:keys [label spec]} value req-value validate?]
|
|
|
|
(defn checkbox-widget [id def value]
|
|
|
|
(list
|
|
|
|
|
|
|
|
(when (and validate? (not (spec/valid? spec req-value)))
|
|
|
|
|
|
|
|
(spec-to-errmsg label spec value))
|
|
|
|
|
|
|
|
(hform/label id label)
|
|
|
|
|
|
|
|
(hform/check-box id
|
|
|
|
(hform/check-box id
|
|
|
|
(and (some? value) (not= 0 value))
|
|
|
|
(and (some? value)
|
|
|
|
(if validate? req-value value))))
|
|
|
|
(not= 0 value))
|
|
|
|
|
|
|
|
value))
|
|
|
|
|
|
|
|
|
|
|
|
(defn render-textarea [id
|
|
|
|
(defn textarea-widget [id def value]
|
|
|
|
{:keys [label required spec]}
|
|
|
|
(hform/text-area {:required (or (:required def) false)}
|
|
|
|
value
|
|
|
|
|
|
|
|
req-value
|
|
|
|
|
|
|
|
validate?]
|
|
|
|
|
|
|
|
(list
|
|
|
|
|
|
|
|
(when (and validate? (not (spec/valid? spec req-value)))
|
|
|
|
|
|
|
|
(spec-to-errmsg label spec value))
|
|
|
|
|
|
|
|
(hform/label id label)
|
|
|
|
|
|
|
|
(hform/text-area {:required (or required false)}
|
|
|
|
|
|
|
|
id
|
|
|
|
id
|
|
|
|
(if validate? req-value value))))
|
|
|
|
value))
|
|
|
|
|
|
|
|
|
|
|
|
(defn render-select [id {:keys [label spec options]} value req-value validate?]
|
|
|
|
(defn select-widget [id def value]
|
|
|
|
(list
|
|
|
|
|
|
|
|
(when (and validate? (not (spec/valid? spec req-value)))
|
|
|
|
|
|
|
|
(spec-to-errmsg label spec value))
|
|
|
|
|
|
|
|
(hform/label id label)
|
|
|
|
|
|
|
|
(hform/drop-down id
|
|
|
|
(hform/drop-down id
|
|
|
|
options
|
|
|
|
(:options def)
|
|
|
|
(if validate? req-value value))))
|
|
|
|
value))
|
|
|
|
|
|
|
|
|
|
|
|
(defn render-multiselect [id
|
|
|
|
(defn multiselect-widget [id def value]
|
|
|
|
{:keys [label spec options]}
|
|
|
|
(let [options (:options def)]
|
|
|
|
value
|
|
|
|
|
|
|
|
req-value
|
|
|
|
|
|
|
|
validate?]
|
|
|
|
|
|
|
|
(list
|
|
|
|
|
|
|
|
(when (and validate? (not (spec/valid? spec req-value)))
|
|
|
|
|
|
|
|
(spec-to-errmsg label spec value))
|
|
|
|
|
|
|
|
(hform/label id label)
|
|
|
|
|
|
|
|
[:select {:multiple "multiple"
|
|
|
|
[:select {:multiple "multiple"
|
|
|
|
:size 5
|
|
|
|
:size 5
|
|
|
|
:name (name id)
|
|
|
|
:name (name id)
|
|
|
|
:id (name id)}
|
|
|
|
:id (name id)}
|
|
|
|
(for [option options]
|
|
|
|
(for [option options]
|
|
|
|
[:option {:value (second option)
|
|
|
|
[:option {:value (second option)
|
|
|
|
:selected (in? (if validate? req-value value)
|
|
|
|
:selected (in? value (second option))}
|
|
|
|
(second option))}
|
|
|
|
|
|
|
|
(first option)])]))
|
|
|
|
(first option)])]))
|
|
|
|
|
|
|
|
|
|
|
|
(def render-mapping
|
|
|
|
(def widget-mapping
|
|
|
|
{:input render-input
|
|
|
|
{:input input-widget
|
|
|
|
:checkbox render-checkbox
|
|
|
|
:checkbox checkbox-widget
|
|
|
|
:textarea render-textarea
|
|
|
|
:textarea textarea-widget
|
|
|
|
:select render-select
|
|
|
|
:select select-widget
|
|
|
|
:mselect render-multiselect})
|
|
|
|
:mselect multiselect-widget})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defn widget
|
|
|
|
|
|
|
|
[id def value req-value validate?]
|
|
|
|
|
|
|
|
(let [{:keys [label spec widget options]} def
|
|
|
|
|
|
|
|
widget (cond (some? widget) widget
|
|
|
|
|
|
|
|
(some? options) :select
|
|
|
|
|
|
|
|
:else :input)
|
|
|
|
|
|
|
|
renderer (widget widget-mapping)]
|
|
|
|
|
|
|
|
(list
|
|
|
|
|
|
|
|
(when (and validate? (not (spec/valid? spec req-value)))
|
|
|
|
|
|
|
|
(spec-to-errmsg label spec req-value))
|
|
|
|
|
|
|
|
(hform/label id label)
|
|
|
|
|
|
|
|
(renderer id def (if validate? req-value value)))))
|
|
|
|
|
|
|
|
|
|
|
|
(defn form-hash [def values]
|
|
|
|
(defn form-hash [def values]
|
|
|
|
(str (hash [def values])))
|
|
|
|
(str (hash [def values])))
|
|
|
@ -158,14 +144,10 @@
|
|
|
|
validate? (= form-hash submitted-hash)]
|
|
|
|
validate? (= form-hash submitted-hash)]
|
|
|
|
(conj (map
|
|
|
|
(conj (map
|
|
|
|
(fn [[field-id field-def]]
|
|
|
|
(fn [[field-id field-def]]
|
|
|
|
(let [{:keys [options widget to-form]} field-def
|
|
|
|
(let [{:keys [options to-form]} field-def
|
|
|
|
value (field-id values)
|
|
|
|
value (field-id values)
|
|
|
|
req-value (get-in req [:params field-id])
|
|
|
|
req-value (get-in req [:params field-id])]
|
|
|
|
widget (cond (some? widget) widget
|
|
|
|
(widget field-id
|
|
|
|
(some? options) :select
|
|
|
|
|
|
|
|
:else :input)
|
|
|
|
|
|
|
|
widget-renderer (widget render-mapping)]
|
|
|
|
|
|
|
|
(widget-renderer field-id
|
|
|
|
|
|
|
|
field-def
|
|
|
|
field-def
|
|
|
|
(if to-form (to-form value) value)
|
|
|
|
(if to-form (to-form value) value)
|
|
|
|
req-value
|
|
|
|
req-value
|
|
|
|