-
Notifications
You must be signed in to change notification settings - Fork 1
/
table.cljs
43 lines (40 loc) · 1.49 KB
/
table.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
(ns ez-wire.form.table
(:require [ez-wire.form.common :as common]
[ez-wire.form.helpers :as helpers]
[ez-wire.util :as util]))
(defn- table-row [{:keys [wiring] :as field} {{label? :label?} :options :as form-map}]
(if wiring
[:$wrapper wiring]
(if (false? label?)
[:tr {:key (str "tr-" (:id field))}
[:td
(common/render-field field form-map)
(common/render-error-element field form-map)
(common/render-text field form-map)
(common/render-help field form-map)]]
[:tr {:key (str "tr-" (:id field))}
[:td
(common/render-label field form-map)]
[:td
(common/render-field (dissoc field :label) form-map)
(common/render-error-element field form-map)
(common/render-text field form-map)
(common/render-help field form-map)]])))
(defn as-table
[params form-map & [content]]
(let [{:keys [id]
:or {id (util/gen-id)}} params
;; generate the body of the table
body (common/get-body table-row params form-map)
re-render? (helpers/re-render? form-map)]
(fn [params form-map & [content]]
(let [{:keys [style class]
:or {style {}
class ""}} params
body (if re-render? (common/get-body table-row params form-map) body)]
[:table {:key (util/slug "form-table" id)
:style style
:class class}
[:tbody body
(if content
[content])]]))))