aesmail / kaffy

Powerfully simple admin package for phoenix applications
https://kaffy.fly.dev/admin/
MIT License
1.34k stars 155 forks source link

[BUG] String Arrays aren't decoded from JSON #271

Closed kevinschweikert closed 1 year ago

kevinschweikert commented 1 year ago

Versions Used Kaffy: 0.9.4 and master Phoenix: 1.7.0 Elixir: 1.14.4

What's actually happening?

String Array Fields can't be saved. Instead, produce an error with [ARRAY_FIELD] is invalid.

What should happen instead?

String Arrays should be editable via a JSON Textfield

Maybe related to #130 or #212

Screenshots image

kevinschweikert commented 1 year ago

I did some debugging and it seems, that the Text Field is still encoded as JSON and that's why the Ecto.Changeset.cast/2 function fails.

Output from attrs in custom update_changeset/2 function

attrs: %{
    ...
    "playout_tags" => "[\"default\", \"test\"]",
    ...
  },
kevinschweikert commented 1 year ago

Seems like the changes from #212 are missing. If i add

def get_map_fields(schema) do
    get_all_fields(schema)
    |> Enum.filter(fn
      {_f, %{type: :map}} ->
        true

+      {_f, %{type: {:array, _}}} ->
+       true
+
      f when is_atom(f) ->
        f == :map

      _ ->
        false
    end)
  end

It works. I will open a PR