-
Notifications
You must be signed in to change notification settings - Fork 3
/
bootstrap4.ex
96 lines (83 loc) · 2.6 KB
/
bootstrap4.ex
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
defmodule PhoenixSimpleForm.Styles.Bootstrap4 do
use PhoenixSimpleForm.StyleHelpers
def default_wrapper(f, name, opts, do: block) do
content_tag :div, wrapper_html(opts, %{class: "form-group"}) do
[
label(f, name, label_translation(f, name), class: "control-label"),
block,
error_tag(f, name)
]
end
end
def input(:text_input, f, name, opts) do
default_wrapper(f, name, opts) do
text_input(f, name, input_html(opts, %{class: "form-control"}))
end
end
def input(:prepend, f, name, opts) do
default_wrapper(f, name, opts) do
content_tag :div, class: "input-group" do
[
content_tag(:span, opts[:prepend_text], class: "input-group-addon"),
text_input(f, name, input_html(opts, %{class: "form-control"}))
]
end
end
end
def input(:file_input, f, name, opts) do
default_wrapper(f, name, opts) do
file_input(f, name, input_html(opts, %{class: "form-control"}))
end
end
def input(:number_input, f, name, opts) do
default_wrapper(f, name, opts) do
number_input(f, name, input_html(opts, %{class: "form-control"}))
end
end
def input(:textarea, f, name, opts) do
default_wrapper(f, name, opts) do
textarea(f, name, input_html(opts, %{class: "form-control"}))
end
end
def input(:select, f, name, opts) do
default_wrapper(f, name, opts) do
select(f, name, opts[:collection], input_html(opts, %{class: "form-control c-select"}))
end
end
def input(:date_select, f, name, opts) do
default_wrapper(f, name, opts) do
date_select(f, name)
end
end
def input(:checkbox_vertical, f, name, opts) do
default_wrapper(f, name, opts) do
checkbox(f, name, input_html(opts, %{class: "form-control"}))
end
end
def input(:checkbox, f, name, opts) do
content_tag :div, wrapper_html(opts, %{class: "checkbox"}) do
[
label(f, name, class: "checkbox") do
[
checkbox(f, name, input_html(opts, %{})), label_translation(f, name)]
end,
error_tag(f, name)
]
end
end
def input(unknown_type, _f, name, _opts) do
raise "Cannot find input with type #{unknown_type} for field #{name}"
end
def error_tag(form, field) do
if error = form.errors[field] do
content_tag :span, translate_error(error), class: "help-block text-danger"
else
{:safe, ""}
end
end
def error_notification(_changeset) do
content_tag :div, class: "alert alert-danger" do
content_tag :p, Gettext.dgettext(WorkshopsDe.Gettext, "forms", "error_notification")
end
end
end