changed CHANGELOG.md
 
@@ -1,9 1,18 @@
1
1
# Changelog
2
2
3
- ## [Unreleased]
4
- Nothing yet
3
## Unreleased
4
- Nothing yet
5
5
6
- ## [v0.4.1] - 2019-09-13
6
## [v0.4.2] - 2016-09-16
7
### Fixed
8
- Strip empty binaries from array of ids before casting ([@sebastian](https://github.com/sebastian))
9
- Properly order nested tags - checkbox first, label text afterwards ([@creuter](https://github.com/creuter))
10
11
## Changed
12
- Improved documentation ([@sebastian](https://github.com/sebastian))
13
14
15
## [v0.4.1] - 2016-09-13
7
16
### Fixed
8
17
- Don't try to pattern match keyword list options ([@drapergeek](https://github.com/drapergeek))
9
18
 
@@ -41,7 50,8 @@ Nothing yet
41
50
- Initial functionality implemented
42
51
43
52
44
- [Unreleased]: https://github.com/adam12/phoenix_mtm/compare/v0.4.1...HEAD
53
[Unreleased]: https://github.com/adam12/phoenix_mtm/compare/v0.4.2...HEAD
54
[v0.4.2]: https://github.com/adam12/phoenix_mtm/compare/v0.4.1...v0.4.2
45
55
[v0.4.1]: https://github.com/adam12/phoenix_mtm/compare/v0.4.0...v0.4.1
46
56
[v0.4.0]: https://github.com/adam12/phoenix_mtm/compare/v0.3.0...v0.4.0
47
57
[v0.3.0]: https://github.com/adam12/phoenix_mtm/compare/v0.2.0...v0.3.0
changed README.md
 
@@ -11,7 11,7 @@ If you are familiar with Ruby on Rails, analogous to `collection_check_boxes`.
11
11
Add phoenix_mtm to your list of dependencies in `mix.exs`:
12
12
13
13
def deps do
14
- [{:phoenix_mtm, "~> 0.4.1"}]
14
[{:phoenix_mtm, "~> 0.4.2"}]
15
15
end
16
16
17
17
## Usage
 
@@ -29,3 29,17 @@ Add phoenix_mtm to your list of dependencies in `mix.exs`:
29
29
30
30
You can pass along attributes directly to the generated inputs and labels by
31
31
passing a keyword list inside both `label_opts` and `input_opts` keys.
32
33
## Contributing
34
35
I love pull requests! If you fork this project and modify it, please ping me to see
36
if your changes can be incorporated back into this project.
37
38
That said, if your feature idea is nontrivial, you should probably open an issue to
39
[discuss it](http://www.igvita.com/2011/12/19/dont-push-your-pull-requests/)
40
before attempting a pull request.
41
42
## License
43
44
MIT License, see [LICENSE](LICENSE.md) file.
45
changed hex_metadata.config
 
@@ -24,4 24,4 @@
24
24
{<<"name">>,<<"postgrex">>},
25
25
{<<"optional">>,true},
26
26
{<<"requirement">>,<<">= 0.0.0">>}]]}.
27
- {<<"version">>,<<"0.4.1">>}.
27
{<<"version">>,<<"0.4.2">>}.
changed lib/phoenix_mtm/changeset.ex
 
@@ -39,24 39,23 @@ defmodule PhoenixMTM.Changeset do
39
39
end
40
40
"""
41
41
def cast_collection(set, assoc, repo, mod) do
42
- case Map.fetch(set.params, to_string(assoc)) do
43
- {:ok, ids} ->
44
- changes =
45
- ids
46
- |> all(repo, mod)
47
- |> Enum.map(&change/1)
48
-
49
- put_assoc(set, assoc, changes)
50
- :error ->
51
- set
52
- end
42
perform_cast(set, assoc, &all(&1, repo, mod))
53
43
end
54
44
55
45
def cast_collection(set, assoc, lookup_fn) when is_function(lookup_fn) do
46
perform_cast(set, assoc, lookup_fn)
47
end
48
49
defp all(ids, repo, mod) do
50
repo.all(from m in mod, where: m.id in ^ids)
51
end
52
53
defp perform_cast(set, assoc, lookup_fn) do
56
54
case Map.fetch(set.params, to_string(assoc)) do
57
55
{:ok, ids} ->
58
56
changes =
59
57
ids
58
|> Enum.reject(&(&1 === ""))
60
59
|> lookup_fn.()
61
60
|> Enum.map(&change/1)
62
61
 
@@ -65,8 64,4 @@ defmodule PhoenixMTM.Changeset do
65
64
set
66
65
end
67
66
end
68
-
69
- defp all(ids, repo, mod) do
70
- repo.all(from m in mod, where: m.id in ^ids)
71
- end
72
67
end
changed lib/phoenix_mtm/helpers.ex
 
@@ -13,11 13,15 @@ defmodule PhoenixMTM.Helpers do
13
13
14
14
## Basic Example
15
15
16
- <%= PhoenixMTM.Helpers.collection_checkboxes f, :tags, Enum.map(@tags, fn tag -> {tag.name, tag.id} end), selected: Enum.map(f.data.tags, &(&1.id)) %>
16
<%= PhoenixMTM.Helpers.collection_checkboxes f, :tags,
17
Enum.map(@tags, &({&1.name, &1.id})),
18
selected: Enum.map(f.data.tags, &(&1.id)) %>
17
19
18
- # Custom <input> and <label> options
20
## Custom `<input>` and `<label>` options
19
21
20
- <%= PhoenixMTM.Helpers.collection_checkboxes f, :tags, Enum.map(@tags, fn tag -> {tag.name, tag.id} end), selected: Enum.map(f.data.tags, &(&1.id)),
22
<%= PhoenixMTM.Helpers.collection_checkboxes f, :tags,
23
Enum.map(@tags, &({&1.name, &1.id})),
24
selected: Enum.map(f.data.tags, &(&1.id)),
21
25
label_opts: [class: "form-input"], input_opts: [class: "form-control"] %>
22
26
23
27
## Options
 
@@ -56,7 60,7 @@ defmodule PhoenixMTM.Helpers do
56
60
if {:nested, true} in opts do
57
61
[
58
62
label form, field, label_opts do
59
- [{:safe, "#{label}"}, input_tag]
63
[input_tag, {:safe, "#{label}"}]
60
64
end
61
65
]
62
66
else
changed mix.exs
 
@@ -3,7 3,7 @@ defmodule PhoenixMTM.Mixfile do
3
3
4
4
def project do
5
5
[app: :phoenix_mtm,
6
- version: "0.4.1",
6
version: "0.4.2",
7
7
elixir: "~> 1.2",
8
8
build_embedded: Mix.env == :prod,
9
9
start_permanent: Mix.env == :prod,