diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/org_ckons_cljs/form/core.cljs | 266 | ||||
| -rw-r--r-- | src/org_ckons_cljs/form/react.cljs | 5 |
2 files changed, 136 insertions, 135 deletions
diff --git a/src/org_ckons_cljs/form/core.cljs b/src/org_ckons_cljs/form/core.cljs index 9c4cc82..05aad3f 100644 --- a/src/org_ckons_cljs/form/core.cljs +++ b/src/org_ckons_cljs/form/core.cljs @@ -6,135 +6,137 @@ (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 form-check-inline"} - [: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") - (when (get form-field "required") - " *")])] - (= (get form-field "fieldType") "select") - [:div {:class "form-group"} - [:label {:for (get form-field "name")} - (get form-field "label") - (when (get form-field "required") - " *")] - [:select {:class "form-control" - :name (get form-field "name") - :id (get form-field "name") - :required (get form-field "required")} - (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") - (when (get form-field "required") - " *")]) - [:div {:class "col-sm-10"} - [:textarea {:class "form-control" - :name (get form-field "name") - :id (get form-field "name") - :rows "10" - :cols "80" - :required (get form-field "required")} - (get form-field "value")]]] - (= (get form-field "fieldType") "ckeditor") - [: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") - (when (get form-field "required") - " *")]) - [:div {:class "col-sm-10"} - [:textarea {:name (get form-field "name") - :id (get form-field "name")} - (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") - (when (get form-field "required") - " *")]) - [: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"}]]] - (= (get form-field "fieldType") "file") - [: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") - (when (get form-field "required") - " *")]) - [:div {:class "col-sm-10"} - [:input {:name (get form-field "name") - :id (get form-field "name") - :type (get form-field "fieldType") - :class "form-control-file" - :required (get form-field "required")}]]] - :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") - (when (get form-field "required") - " *")]) - [: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" - :placeholder (get form-field "placeholder") - :required (get form-field "required")}]]]))] - (when (get jsonobj "requiredP") - [:div "* Required"])) + (when jsonobj + (let [form-name (str/replace (get jsonobj "name") "-" "_")] + [:div + [: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 (str form-name "-" (get form-field "name")) + :id (str form-name "-" (get form-field "name")) + :value (get form-field "value") + :type (get form-field "fieldType")}] + (= (get form-field "fieldType") "checkbox") + [:div {:class "form-check form-check-inline"} + [:input {:type "checkbox" + :class "form-check-input" + :id (str form-name "-" (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") + (when (get form-field "required") + " *")])] + (= (get form-field "fieldType") "select") + [:div {:class "form-group"} + [:label {:for (get form-field "name")} + (get form-field "label") + (when (get form-field "required") + " *")] + [:select {:class "form-control" + :name (str form-name "-" (get form-field "name")) + :id (str form-name "-" (get form-field "name")) + :required (get form-field "required")} + (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") + (when (get form-field "required") + " *")]) + [:div {:class "col-sm-10"} + [:textarea {:class "form-control" + :name (str form-name "-" (get form-field "name")) + :id (str form-name "-" (get form-field "name")) + :rows "10" + :cols "80" + :required (get form-field "required")} + (get form-field "value")]]] + (= (get form-field "fieldType") "ckeditor") + [: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") + (when (get form-field "required") + " *")]) + [:div {:class "col-sm-10"} + [:textarea {:name (str form-name "-" (get form-field "name")) + :id (str form-name "-" (get form-field "name"))} + (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") + (when (get form-field "required") + " *")]) + [:div {:class "col-sm-10"} + [:input {:name (str form-name "-" (get form-field "name")) + :id (str form-name "-" (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"}]]] + (= (get form-field "fieldType") "file") + [: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") + (when (get form-field "required") + " *")]) + [:div {:class "col-sm-10"} + [:input {:name (str form-name "-" (get form-field "name")) + :id (str form-name "-" (get form-field "name")) + :type (get form-field "fieldType") + :class "form-control-file" + :required (get form-field "required")}]]] + :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") + (when (get form-field "required") + " *")]) + [:div {:class "col-sm-10"} + [:input {:name (str form-name "-" (get form-field "name")) + :id (str form-name "-" (get form-field "name")) + :value (get form-field "value") + :type (get form-field "fieldType") + :class "form-control" + :placeholder (get form-field "placeholder") + :required (get form-field "required")}]]]))] + (when (get jsonobj "requiredP") + [:div "* Required"])]))) diff --git a/src/org_ckons_cljs/form/react.cljs b/src/org_ckons_cljs/form/react.cljs index a46cd42..fecfbcf 100644 --- a/src/org_ckons_cljs/form/react.cljs +++ b/src/org_ckons_cljs/form/react.cljs @@ -1,7 +1,7 @@ (ns org-ckons-cljs.form.react (:require-macros [clojure.string :as str])) -(defn react-generic-form [jsonobj namespace] +(defn react-generic-form [jsonobj namespace onclick-fn] [:div [:div {:id "form-errormsg"}] [:form {:name (get jsonobj "name") @@ -16,8 +16,7 @@ [:button {:class "btn btn-primary" :data-dismiss (get jsonobj "dismiss") :type (cond (get form-field "onclick") "button" :else "submit") - :on-click (when (get form-field "onclick") - (str namespace "." (get form-field "onclick")))} + :on-click onclick-fn} (get form-field "label")]]] (= (get form-field "fieldType") "hidden") [:input {:name (get form-field "name") |
