add hidden widget

master
Josha von Gizycki 6 years ago
parent 4eeb4bb4c7
commit 6ea09ca7f4

@ -94,12 +94,16 @@
:selected (in? value (second option))}
(first option)])]))
(defn hidden-widget [id def value]
(hform/hidden-field id value))
(def widget-mapping
{:input input-widget
:checkbox checkbox-widget
:textarea textarea-widget
:select select-widget
:mselect multiselect-widget})
:mselect multiselect-widget
:hidden hidden-widget})
(defn widget-markup
[id def value req-value validate?]

@ -186,6 +186,31 @@
(nthrest
(render-widgets def {} {})
2))))))
(testing "hidden is rendered correctly"
(let [def {:fields {:foo-id {:label "foo-label"
:widget :hidden}}}]
(is (= (list nil
[:label {:for "foo-id"} "foo-label"]
[:input {:id "foo-id"
:type "hidden"
:name "foo-id"
:value nil}])
(first
(nthrest
(render-widgets def {} {})
2)))))
(let [def {:fields {:foo-id {:label "foo-label"
:widget :hidden}}}]
(is (= (list nil
[:label {:for "foo-id"} "foo-label"]
[:input {:id "foo-id"
:type "hidden"
:name "foo-id"
:value "4711"}])
(first
(nthrest
(render-widgets def {:foo-id "4711"} {})
2))))))
(testing "mselect is rendered correctly"
(let [def {:fields {:foo-id {:label "foo-label"
:widget :mselect
@ -204,3 +229,32 @@
(nthrest
(render-widgets def {} {})
2)))))))
(deftest to-form-is-used
(testing "data passed to fo-form is taken from values"
(let [def {:fields {:foo {:label ""
:to-form (partial str "4711")}}}]
(is (= (list nil
[:label {:for "foo"} ""]
[:input {:id "foo"
:name "foo"
:value "4711abc"
:required false
:type "text"}])
(first
(nthrest
(render-widgets def {:foo "abc"} {})
2)))))
(let [def {:fields {:foo {:label ""
:to-form (partial str "4711")}}}]
(is (= (list nil
[:label {:for "foo"} ""]
[:input {:id "foo"
:name "foo"
:value "4711abc"
:required false
:type "text"}])
(first
(nthrest
(render-widgets def {:foo "abc"} {:params {:foo "def"}})
2)))))))

Loading…
Cancel
Save