Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
hiram-madelaine committed Jul 15, 2015
2 parents 59d11f1 + f2844b8 commit 9a6c18b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/om_inputs/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[schema.core :as s :include-macros true]
[schema.coerce :as coerce]
[clojure.string :as str]
[om-inputs.utils :refer [full-name]]
[om-inputs.utils :refer [full-name ->int]]
[om-inputs.date-utils :as d]
[om-inputs.schema-utils :as su :refer [sch-type]]
[om-inputs.schemas :refer [sch-business-state sch-field-state SchOptions]]
Expand Down Expand Up @@ -135,24 +135,28 @@
(defmethod magic-input "stepper"
[{{:keys [attrs k]} :opts chan :chan}]
(let [{:keys [min max step value size]} attrs
value (->int value)
min (->int min)
max (->int max)
step (->int step)
plus (if step (partial + (long step)) inc)
minus (if step (partial + (- (long step))) dec)
style (styles "btn btn-default" (when size (str "btn-" size)))]
(dom/div (clj->js (merge attrs {:className "btn-group stepper"}))
(dom/div (clj->js (merge attrs {:className "btn-group stepper"}))
(dom/button #js {:type "button"
:className style
:onClick #(when (or (nil? min)
(and min (<= (int min) (minus value))))
(put! chan [k (minus value)]))} "-")
:onClick #(when (or (nil? min)
(and min (<= (int min) (minus value))))
(put! chan [k (str (minus value))]))} "-")
(dom/input #js {:className "input-stepper"
:size (if (str/blank? value) 1 (count (str value)))
:value value})

(dom/button #js {:type "button"
:className style
:onClick #(when (or (nil? max)
(and max (<= (plus value) (int max))))
(put! chan [k (plus value)]))} "+"))))
:onClick #(when (or (nil? max)
(and max (<= (plus value) (int max))))
(put! chan [k (str (plus value))]))} "+"))))


#_(defmethod magic-input s/Inst
Expand Down
12 changes: 12 additions & 0 deletions src/om_inputs/utils.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@
[om.dom :as dom :include-macros true]))



;_________________________________________________
; |
; Interop Utils |
;_________________________________________________|


(defn ->int [s]
(when-not (str/blank? s) (js/parseInt s 10)))


;_________________________________________________
; |
; Clojure Utils |
Expand All @@ -19,6 +30,7 @@




;_________________________________________________
; |
; Display Utils |
Expand Down

0 comments on commit 9a6c18b

Please sign in to comment.