From a6edab6f09845b80792276f3ddd5cef84e6dbfcc Mon Sep 17 00:00:00 2001 From: ckonstanski Date: Sun, 9 Aug 2026 12:14:30 -0600 Subject: add react version --- src/org_ckons_cljs/form/react.cljs | 138 +++++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 src/org_ckons_cljs/form/react.cljs (limited to 'src/org_ckons_cljs/form') diff --git a/src/org_ckons_cljs/form/react.cljs b/src/org_ckons_cljs/form/react.cljs new file mode 100644 index 0000000..b724409 --- /dev/null +++ b/src/org_ckons_cljs/form/react.cljs @@ -0,0 +1,138 @@ +(ns org-ckons-cljs.form.react + (:require-macros [clojure.string :as str])) + +(defn react-generic-form [jsonobj namespace] + [:div + [: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") + :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") + (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" + :required (get form-field "required")}]]]))] + (when (get jsonobj "requiredP") + [:div "* Required"])]) -- cgit v1.3