                         [:div])]])))
 
 
-(defn consolidation-tags-template [data-set]
-  (cond (nil? (:villageid @data-set)) [:select.form-control {:id "consolidation-districts"}
-                                       (for [d (get-value! :villages)]
-                                         ^{:key (.-id d)} [:option {:value (.-id d)} (.-villagename d)])]
-        :else [:select.form-control {:id "consolidation-districts" :defaultValue (:villageid @data-set)}
-               (doall (for [d (get-value! :villages)]
-                        ^{:key (.-id d)} [:option {:value (.-id d)} (.-villagename d)]))]))
-
-(defn consolidation-input-select [label 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 [consolidation-tags-template data-set]]
-       [:div.col-sm-3 [:div]]])))
-
+(defn cons-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 cons-sub-sel-tag [id data data-set]
+  [:select.form-control {:id id
+                         :value (@data-set id)
+                         :on-change #(cons-sub-onchange  id (-> % .-target .-value) data-set)}
+   [:option {:value 0} "--Select--"]
+   (for [d  data]
+     ^{:key (.-id d) }
+     [:option {:value (.-id d)} (.-subdivisionname d)])])
+
+(defn cons-form-sub-sel [label id opt-data data-set]
+  [:div.form-group
+   [:label.col-sm-3.control-label label]
+   [:div.col-sm-6 [cons-sub-sel-tag id opt-data data-set]]
+   [:div.col-sm-3 [:div]]])
+
+
+(defn cons-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 cons-form-villages-sel [label id opt-data data-set]
+  [:div.form-group
+   [:label.col-sm-3.control-label label]
+   [:div.col-sm-6 [cons-villages-sel-tag id opt-data data-set]]
+   [:div.col-sm-3 [:div]]])
 
 (defn consolidation-form-cancel [event]
   (accountant/navigate! "/consolidation"))
-
-(defn consolidation-add [event]
-  (accountant/navigate! "/consolidation/add"))
 
 (defn consolidation-template [doc-name data-set focus save-function]
   [:div.container

     [:div.form-horizontal
      [:div.box-body
       [fieldbook-input-int-row :serialnumber "Serial Number" "text" data-set focus]
       [fieldbook-input-select "Village Name" data-set focus ]
       [fieldbook-input-row :subdivisionname "Sub Division Name" "text" data-set focus]
       [fieldbook-input-row :tehsil "Tehsil" "text" data-set focus]
       [fieldbook-input-int-row :year "Year" "text" data-set focus]
       [fieldbook-input-row :racknumber "Rack Number" "text" data-set focus]
       [fieldbook-input-row :description "Description" "text" data-set focus]

(defroute fieldbook-add-path "/fieldbook/add" []
  (if (nil? (get-value! :user)) (accountant/navigate! "/login")
      (let [onres (fn[json](
                           (set-key-value :subdivisions (getdata json))
                           (set-page! [fieldbook-add-template])))]
        (http-get-auth (str serverhost "subdivisions") onres))))

(defroute fieldbook-upd-path "/fieldbook/update/:id" [id]
  (let [onres (fn[json](
                       (set-key-value :villages (getdata json))
                       (set-page! [fieldbook-update-template id
                                   (first (filter (fn[obj]
                                                    (=(.-id obj) (.parseInt js/window id))) (get-value! :fieldbooks)))])))
        sub-res (fn[json](set-key-value :subdivisions (getdata json)))]
    (do
      (http-get-auth (str serverhost "villages") onres)
      (http-get-auth (str serverhost "subdivisions") sub-res))))

(defn fieldbook-add [event]
  (accountant/navigate! "/fieldbook/add"))



(defn render-fieldbook [fieldbooks]
  [:div.col-md-12
   [:div {:class "box"}
    [:div {:class "box-header"}
     [:h3.box-title "List of fieldbook"]]
    [:div.box-body
      [:div.form-group
       [:input {:type "button" :value "Add"
