Back
with-group (clj)
(source)macro
(with-group group & body)
Group together a set of related form fields for use with the Ring
nested-params middleware.
Examples
hiccup
(ns hiccup.form_test
(:require [clojure.test :refer :all]
[hiccup.core :refer [html]]
[hiccup.form :refer :all]))
(deftest test-with-group
(testing "hidden-field"
(is (= (html (with-group :foo (hidden-field :bar "val")))
"<input id=\"foo-bar\" name=\"foo[bar]\" type=\"hidden\" value=\"val\" />")))
(testing "text-field"
(is (= (html (with-group :foo (text-field :bar)))
"<input id=\"foo-bar\" name=\"foo[bar]\" type=\"text\" />")))
(testing "checkbox"
(is (= (html (with-group :foo (check-box :bar)))
"<input id=\"foo-bar\" name=\"foo[bar]\" type=\"checkbox\" value=\"true\" />")))
(testing "password-field"
(is (= (html (with-group :foo (password-field :bar)))
"<input id=\"foo-bar\" name=\"foo[bar]\" type=\"password\" />")))
(testing "radio-button"
(is (= (html (with-group :foo (radio-button :bar false "val")))
"<input id=\"foo-bar-val\" name=\"foo[bar]\" type=\"radio\" value=\"val\" />")))
(testing "drop-down"
(is (= (html (with-group :foo (drop-down :bar [])))
(str "<select id=\"foo-bar\" name=\"foo[bar]\"></select>"))))
(testing "text-area"
(is (= (html (with-group :foo (text-area :bar)))
(str "<textarea id=\"foo-bar\" name=\"foo[bar]\"></textarea>"))))
(testing "file-upload"
(is (= (html (with-group :foo (file-upload :bar)))
"<input id=\"foo-bar\" name=\"foo[bar]\" type=\"file\" />")))
(testing "label"
(is (= (html (with-group :foo (label :bar "Bar")))
"<label for=\"foo-bar\">Bar</label>")))
(testing "multiple with-groups"
(is (= (html (with-group :foo (with-group :bar (text-field :baz))))
"<input id=\"foo-bar-baz\" name=\"foo[bar][baz]\" type=\"text\" />")))
(testing "multiple elements"
(is (= (html (with-group :foo (label :bar "Bar") (text-field :var)))
"<label for=\"foo-bar\">Bar</label><input id=\"foo-var\" name=\"foo[var]\" type=\"text\" />"))))
weavejester/hiccup
(ns hiccup.form_test
(:require [clojure.test :refer :all]
[hiccup.core :refer [html]]
[hiccup.form :refer :all]))
(deftest test-with-group
(testing "hidden-field"
(is (= (html (with-group :foo (hidden-field :bar "val")))
"<input id=\"foo-bar\" name=\"foo[bar]\" type=\"hidden\" value=\"val\" />")))
(testing "text-field"
(is (= (html (with-group :foo (text-field :bar)))
"<input id=\"foo-bar\" name=\"foo[bar]\" type=\"text\" />")))
(testing "checkbox"
(is (= (html (with-group :foo (check-box :bar)))
"<input id=\"foo-bar\" name=\"foo[bar]\" type=\"checkbox\" value=\"true\" />")))
(testing "password-field"
(is (= (html (with-group :foo (password-field :bar)))
"<input id=\"foo-bar\" name=\"foo[bar]\" type=\"password\" />")))
(testing "radio-button"
(is (= (html (with-group :foo (radio-button :bar false "val")))
"<input id=\"foo-bar-val\" name=\"foo[bar]\" type=\"radio\" value=\"val\" />")))
(testing "drop-down"
(is (= (html (with-group :foo (drop-down :bar [])))
(str "<select id=\"foo-bar\" name=\"foo[bar]\"></select>"))))
(testing "text-area"
(is (= (html (with-group :foo (text-area :bar)))
(str "<textarea id=\"foo-bar\" name=\"foo[bar]\"></textarea>"))))
(testing "file-upload"
(is (= (html (with-group :foo (file-upload :bar)))
"<input id=\"foo-bar\" name=\"foo[bar]\" type=\"file\" />")))
(testing "label"
(is (= (html (with-group :foo (label :bar "Bar")))
"<label for=\"foo-bar\">Bar</label>")))
(testing "multiple with-groups"
(is (= (html (with-group :foo (with-group :bar (text-field :baz))))
"<input id=\"foo-bar-baz\" name=\"foo[bar][baz]\" type=\"text\" />")))
(testing "multiple elements"
(is (= (html (with-group :foo (label :bar "Bar") (text-field :var)))
"<label for=\"foo-bar\">Bar</label><input id=\"foo-var\" name=\"foo[var]\" type=\"text\" />"))))
asmala/clj-simple-form
(ns clj-simple-form.giddyup
"Scope functions for Hiccup interoperability. Requiring this namespace sets
the form HTML functions to the contents of `giddyup.forms`."
(:use [clj-simple-form.util :only [set-html-fns!]])
(:require [giddyup.forms]
[clj-simple-form.form-scope :as form-scope]
[hiccup.form :as f]))
(with-form-scope :profile {:email \"joe@example.com\"} {}
(email-field-input :email))"
[object values errors & content]
`(->> (f/with-group ~object ~@content)
(form-scope/with-form-scope ~object ~values ~errors)))
(with-form-scope :profile {} {:address {:street \"is required\"}}
(with-nested-form-scope :address
(text-field-input :street)))"
[object & content]
`(->> (f/with-group ~object ~@content)
(form-scope/with-nested-form-scope ~object)))