(ns org-ckons-cljs.form.react (:require-macros [clojure.string :as str])) (defn react-generic-form [jsonobj namespace onclick-fn] [: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") :on-click onclick-fn} (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"])])