diff options
| author | ckonstanski <ckonstanski@pippiandcarlos.com> | 2020-12-25 22:29:00 -0700 |
|---|---|---|
| committer | ckonstanski <ckonstanski@pippiandcarlos.com> | 2020-12-25 22:29:00 -0700 |
| commit | 26986b0c67cd05be90ab52b0f6080a2ba6fa48bb (patch) | |
| tree | 64ddd7314746642c3035b147a20078398df9aad7 /src/org_ckons_cljs | |
initial import
Diffstat (limited to 'src/org_ckons_cljs')
| -rw-r--r-- | src/org_ckons_cljs/form/core.cljs | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/src/org_ckons_cljs/form/core.cljs b/src/org_ckons_cljs/form/core.cljs new file mode 100644 index 0000000..1233ce5 --- /dev/null +++ b/src/org_ckons_cljs/form/core.cljs @@ -0,0 +1,100 @@ +(ns org-ckons-cljs.form.core + (:require-macros [hiccups.core :as hiccups :refer [html]] + [clojure.string :as str])) + +(declare template-generic-form) + +(hiccups/defhtml template-generic-form [jsonobj namespace] + [:div {:id "form-errormsg"}] + [:form {:name (get jsonobj "name") + :id (get jsonobj "name") + :method (get jsonobj "httpMethod") + :action (when (get jsonobj "action") + (str "javascript:" namespace "." (get jsonobj "action")))} + (for [form-field (get jsonobj "formFields")] + (cond (= (get form-field "fieldType") "button") + [:div {:class "form-group row"} + [:div {:class "offset-sm-2 col-sm-10"} + [:button {:class "btn btn-primary" + :data-dismiss (get jsonobj "dismiss") + :type (cond (get form-field "onclick") "button" :else "submit") + :onclick (when (get form-field "onclick") + (str namespace "." (get form-field "onclick")))} + (get form-field "label")]]] + (= (get form-field "fieldType") "hidden") + [:input {:name (get form-field "name") + :id (get form-field "name") + :value (get form-field "value") + :type (get form-field "fieldType")}] + (= (get form-field "fieldType") "checkbox") + [:div {:class "form-check"} + [:input {:type "checkbox" + :class "form-check-input" + :id (get form-field "name") + :value (get form-field "value") + :checked (get form-field "checked") + :required (get form-field "required")}] + (when (get form-field "label") + [:label {:class "form-check-label" + :for (get form-field "name")} + (get form-field "label")])] + (= (get form-field "fieldType") "select") + [:div {:class "form-group"} + [:label {:for (get form-field "name")} + (get form-field "label")] + [:select {:class "form-control" + :name (get form-field "name") + :id (get form-field "name") + :required (get form-field "required") + :onchange (when (get form-field "onchange") + (str namespace "." (get form-field "onchange")))} + (for [option (get form-field "options")] + [:option {:value (get option "value") + :selected (when (= (get option "value") (get form-field "value")) + "selected")} + (get option "label")])]] + (= (get form-field "fieldType") "textarea") + [:div {:class "form-group row"} + (when (get form-field "label") + [:label {:for (get form-field "name") + :class "col-form-label col-sm-2" + :style "text-align: right"} + (get form-field "label")]) + [:div {:class "col-sm-10"} + [:textarea {:name (get form-field "name") + :id (get form-field "name") + :rows "10" + :cols "68"} + (get form-field "value")]]] + (= (get form-field "fieldType") "datetime-local") + [:div {:class "form-group row"} + (when (get form-field "label") + [:label {:for (get form-field "name") + :class "col-form-label col-sm-2" + :style "text-align: right"} + (get form-field "label")]) + [:div {:class "col-sm-10"} + [:input {:name (get form-field "name") + :id (get form-field "name") + :value (get form-field "value") + :type (get form-field "fieldType") + :class "form-control" + :required (get form-field "required") + :min "2018-01-01T00:00" + :max "2020:12-31T23:59"}]]] + :else + [:div {:class "form-group row"} + (when (get form-field "label") + [:label {:for (get form-field "name") + :class "col-form-label col-sm-2" + :style "text-align: right"} + (get form-field "label")]) + [:div {:class "col-sm-10"} + [:input {:name (get form-field "name") + :id (get form-field "name") + :value (get form-field "value") + :type (get form-field "fieldType") + :class "form-control" + :required (get form-field "required")}]]]))] + (when (get jsonobj "requiredP") + [:div "* Required"])) |
