Skip to content

Instantly share code, notes, and snippets.

Created October 17, 2015 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/1f0ee193577c8ec7d09d to your computer and use it in GitHub Desktop.
Save anonymous/1f0ee193577c8ec7d09d to your computer and use it in GitHub Desktop.
(ns astro.comp.home-birth
(:require [reagent.core :as r :refer [atom]]
[astro.menu-data :as m]
[astro.comp.add-link :as al :refer [cities-menu]]
[ajax.core :refer [GET POST]]))
(def form-data (r/atom {}))
(def res (r/atom nil))
(defn error-handler [{:keys [status status-text]}] (.log js/console (str "Error: " status " " status-text)))
(defn submit-form []
(POST "/register" {:headers {"Accept" "application/transit+json"
"x-csrf-token" (.-value (.getElementById js/document "token"))}
:params @form-data
:handler #(reset! res %)
:error-handler error-handler}))
(defn resp [] (when @res [:div [:h2 (@res :h2)] [:p (@res :text)]]))
(defn cmp []
(let [selected-region (r/atom "")]
(fn []
[:form
[:input.box.name_box {:id "first_name" :name "first_name" :on-change #(swap! form-data assoc :first_name (.-value (.-target %)))}]
[:input.box.name_box {:id "surname" :name "surname" :on-change #(swap! form-data assoc :surname (.-value (.-target %)))}]
[:input.box.name_box {:id "email" :name "email" :on-change #(swap! form-data assoc :email (.-value (.-target %)))}]
[:input.box.name_box {:id "password1" :name "password1" :on-change #(swap! form-data assoc :password1 (.-value (.-target %)))}]
[:input.box.name_box {:id "password2" :name "password2" :on-change #(swap! form-data assoc :password2 (.-value (.-target %)))}]
[:h3 "Birth Details"]
[:span.box.select_box (m/menu "day" "Day" 1 32)]
[:span.box.select_box (m/menu "month" "Month" 1 13)]
[:span.box.select_box (m/menu "year" "Year" 1920 2017)]
[:span.box.select_box (m/menu "hour" "Hour" 10 24)]
[:span.box.select_box (m/menu "min" "Minute" 10 60)]
[:select {:id "region" :name "region" :on-change #(do (reset! selected-region (.-value (.-target %)))
(swap! form-data assoc :region (.-value (.-target %))))}
[:option {:value ""} "Region"]
(for [r m/regions] [:option {:value r} r])]
(when (not (empty? @selected-region)) (al/cities-menu @selected-region))
[:input {:id "signup" :type "submit" :on-click submit-form}]])))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment