                            [:b (str (first ((o6register-form-validator @data-set) id)))]])
                         [:div])]])))
 
-
-(defn set-o6-fields [data-set mutdata]
-  (do
-    (swap! data-set assoc :subdivisionname (.-subdivisionname mutdata))
-    (swap! data-set assoc :mutationid (int (.-id mutdata)))
-    (swap! data-set assoc :villagename (.-villagename mutdata))))
-
-
-(defn reset-o6-fields [data-set]
-  (do
-    (swap! data-set assoc :subdivisionname nil)
-    (swap! data-set assoc :mutationid nil)
-    (swap! data-set assoc :villagename "")
-    (swap! data-set assoc :o6number nil)))
-
-(defn on-o6-change [data-set]
-  (let [selval (.-value (.getElementById js/document "O6-select"))
-        onres (fn [json] (let [d (first (getdata json))]
-                          (set-o6-fields data-set d)))]
-    (if (= selval "select") (reset-o6-fields data-set)
-        (http-get-auth (str serverhost "o6registers/"selval"/mutations")
-                       onres))))
-
-
-(defn o6-select
-  [data-set]
-  [:div.form-group
-   [:label.col-sm-3.control-label "O6 Number"]
-   [:div.col-sm-6
-    [:select.form-control {:id "O6-select" :value (:o6number @data-set) :on-change #(on-o6-change data-set)}
-     (for [d (get-value! :o6mutations)]
-       ^{:key (.-id d)} [:option {:value (.-o6number d)} (.-o6number d)])]]])
-
-
-(defn o6register-form-cancel [event]
-  (accountant/navigate! "/o6register"))
-
-
-(defn o6register-tags-template [data-set]
-  [:select.form-control {:id "o6register-districts" :value (:villagename @data-set)}
-   (doall (for [d (get-value! :villages)]
-            ^{:key (.-id d)} [:option {:value (.-villagename d)} (.-villagename d)]))])
-
-(defn o6register-input-select [label data-set focus]
+(defn o6register-input-int-row [id label ttype data-set focus]
   (let [input-focus (r/atom nil)]
     (fn []
       [:div.form-group
        [:label.col-sm-3.control-label label]
-       [:div#tagdiv.col-sm-6 [o6register-tags-template data-set]]
-       [:div.col-sm-3 [:div]]])))
+       [:div.col-sm-6 [input-int id ttype data-set label input-focus]]
+       [:div.col-sm-3 (if (or @input-focus @focus)
+                        (if (= nil (o6register-form-validator @data-set))
+                          [:div]
+                          [:div {:style  {:color "red"}}
+                           [:b (str (first ((o6register-form-validator @data-set) id)))]])
+                        [:div])]])))
+
+
+(defn o6register-form-cancel [event]
+  (accountant/navigate! "/o6register"))
+
+(defn o6num-sel-tag [id data data-set ]
+  [:select.form-control {:id id
+                         :value (@data-set id)
+                         :on-change #(swap! data-set assoc id  (-> % .-target .-value))}
+   [:option {:value 0} "--Select--"]
+   (for [d  data]
+     ^{:key  (.-id d)}
+     [:option {:value (.-o6number d)} (.-o6number d)])])
+
+
+(defn o6-form-o6num-sel [label id opt-data data-set]
+  [:div.form-group
+   [:label.col-sm-3.control-label label]
+   [:div.col-sm-6 [o6num-sel-tag id opt-data data-set]]
+   [:div.col-sm-3 [:div]]])
+
+(defn o6-subdiv-sel-tag [id data data-set ]
+  [:select.form-control {:id id
+                         :value (@data-set id)
+                         :on-change #(swap! data-set assoc id  (-> % .-target .-value))}
+   [:option {:value 0} "--Select--"]
+   (for [d  data]
+     ^{:key (.-id d) }
+     [:option {:value (.-subdivisionname d)} (.-subdivisionname d)])])
+
+(defn o6-form-subdiv-sel [label id opt-data data-set]
+  [:div.form-group
+   [:label.col-sm-3.control-label label]
+   [:div.col-sm-6 [o6-subdiv-sel-tag id opt-data data-set]]
+   [:div.col-sm-3 [:div]]])
+
 
 (defn o6register-template [doc-name data-set focus save-function]
   [:div.container

       [upd-check-input-element data-set focus bool]
       ]
      [:div.box-footer
       [:div.col-sm-12.col-md-offset-5 
        [button-tool-bar
         [button {:bs-style "success" :on-click save-function } "Save"]
         [button {:bs-style "danger" :on-click form-cancel } "Cancel"]]]]

                           [:b (str (first ((o4register-form-validator @data-set) id)))]])
                        [:div])]])))

(defn o4register-input-int-row [id label ttype data-set focus]
  (let [input-focus (r/atom nil)]
    (fn []
      [:div.form-group
       [:label.col-sm-3.control-label label]
       [:div.col-sm-6 [input-int id ttype data-set label input-focus]]
       [:div.col-sm-3 (if (or @input-focus @focus)
                        (if (= nil (o4register-form-validator @data-set))
                          [:div]
                          [:div {:style  {:color "red"}}
                           [:b (str (first ((o4register-form-validator @data-set) id)))]])
                        [:div])]])))


(defn o4register-form-cancel [event]
  (accountant/navigate! "/o4register"))

(defn o4num-sel-tag [id data data-set ]
  [:select.form-control {:id id
                         :value (@data-set id)
                         :on-change #(swap! data-set assoc id  (-> % .-target .-value))}
   [:option {:value 0} "--Select--"]
   (for [d  data]
     ^{:key  (.-id d)}
     [:option {:value (.-o4number d)} (.-o4number d)])])


(defn o4-form-o4num-sel [label id opt-data data-set]
  [:div.form-group
   [:label.col-sm-3.control-label label]
   [:div.col-sm-6 [o4num-sel-tag id opt-data data-set]]
   [:div.col-sm-3 [:div]]])

(defn o4-sub-onchange [id val data-set]
  (let [res (fn [json]
              (let [dt (getdata json)]
                (set-key-value :villages dt)))]
    (do (http-get-auth (str serverhost "subdivisions/" val  "/villages") res)
        (swap! data-set assoc id (js/parseInt val)))))

(defn o4-sub-sel-tag [id data data-set]
  [:select.form-control {:id id
                         :value (@data-set id)
                         :on-change #(rev-sub-onchange  id (-> % .-target .-value) data-set)}
   [:option {:value 0} "--Select--"]
   (for [d  data]
     ^{:key (.-id d) }
     [:option {:value (.-id d)} (.-subdivisionname d)])])

(defn o4-form-sub-sel [label id opt-data data-set]
  [:div.form-group
   [:label.col-sm-3.control-label label]
   [:div.col-sm-6 [o4-sub-sel-tag id opt-data data-set]]
   [:div.col-sm-3 [:div]]])


(defn o4-villages-sel-tag [id data data-set ]
  [:select.form-control {:id id
                         :value (@data-set id)
                         :on-change #(swap! data-set assoc id (js/parseInt (-> % .-target .-value)))}
   [:option {:value 0} "--Select--"]
   (for [d  data]
     ^{:key (.-id d) }
     [:option {:value (.-id d)} (.-villagename d)])])

(defn o4-form-villages-sel [label id opt-data data-set]
  [:div.form-group
   [:label.col-sm-3.control-label label]
   [:div.col-sm-6 [o4-villages-sel-tag id opt-data data-set]]
   [:div.col-sm-3 [:div]]])


(defn o4register-template [doc-name data-set focus save-function]
