This repository has been archived by the owner on Oct 31, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
input.cljs
50 lines (44 loc) · 1.4 KB
/
input.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
(ns re-frame-forms.input
(:require
[re-frame-forms.core :as form]))
(defn radio
([field value]
(radio field value {}))
([field value attrs]
(fn [field value attrs]
[:input (merge attrs
{:type "radio"
:value value
:on-change (form/handle-str-value field)
:checked (= @(form/value field) value)})])))
(defn checkbox
([field]
(checkbox field {}))
([field attrs]
(fn [field attrs]
[:input (merge attrs
{:type "checkbox"
:checked @(form/value field)
:on-change (form/handle-checked-value field)})])))
(defn input
([field]
(input field {:type "text"}))
([field attrs]
(fn [field attrs]
[:input (merge attrs
{:value @(form/str-value field)
:on-change (form/handle-str-value field true)
:on-blur (form/handle-str-value field false)})])))
(defn select
([field attrs options]
(fn [field attrs options]
(into [:select
(merge attrs
{:value @(form/str-value field)
:on-change (form/handle-str-value field)})]
options))))
(defn options [& options]
(->> (partition 2 options)
(mapv (fn [[value label]]
^{:key value}
[:option {:value value} label]))))