Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] expected a map, got: nil when using custom form_field #256

Open
davidahmed opened this issue Jan 2, 2023 · 6 comments
Open

[BUG] expected a map, got: nil when using custom form_field #256

davidahmed opened this issue Jan 2, 2023 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@davidahmed
Copy link

Versions Used
Kaffy: 0.9.4
Phoenix: 1.6.9
Elixir: 1.14.2

What's actually happening?
If I configure resources manually, I get error on edit, create, or update.

expected a map, got: nil when using custom form_field

Here's the configuration I am using:

config :kaffy,
  admin_title: "MyApp Admin",
  otp_app: :my_app,
  ecto_repo: MyApp.Repo,
  router: MyAppWeb.Router,
  resources: &MyApp.Kaffy.Config.create_resources/1

If I don't use resources in config, then everything works. However, I need to have custom form fields for some resources.

This is one of my configurations:

defmodule MyApp.Kaffy.BenchmarkAdmin do
@doc """

"""  
  def form_fields(_) do
    [
      friendly_name: nil,
      stages: nil,
      organization_id: nil
    ]
  end
end

Here's the Config.create_resources

defmodule MyApp.Kaffy.Config do
  def create_resources(_conn) do
    [
     ...
      benchmarks: [
        name: "Benchmarks",
        resources: [
          benchmarks: [schema: MyApp.Benchmarks.Benchmark, admin: MyApp.Kaffy.BenchmarkAdmin], 
          #even if I don't pass `:admin`, the views don't work for creating/ updating resources.
          benchmark_stages: [schema: MyApp.Benchmarks.BenchmarkStage],
        ]
      ]
     ]
  end
end

What should happen instead?
The resource should be created with the given parameters (NOTE: the changeset only requires friendly_name but apparently even that is nil.)

Screenshots
If applicable, add screenshots to help explain your problem.
Screen Shot 2023-01-02 at 15 37 28

@davidahmed davidahmed added the bug Something isn't working label Jan 2, 2023
@aesmail
Copy link
Owner

aesmail commented Jan 2, 2023

Can you please do the following and see if it works:

  • Remove the resources option from Kaffy's configs.
  • Rename the BenchmarkAdmin module from MyApp.Kaffy.BenchmarkAdmin to MyApp.Benchmarks.BenchmarkAdmin

If this works, then Kaffy has a bug with explicit resources. If it doesn't work, at least we know this is not the issue and we can remove it from the list.

@davidahmed
Copy link
Author

Remove the resources option from Kaffy's configs.

If you meant the following, then yeah I've removed and it works. But as many_to_many association is still not supported by Kaffy, those models break the default admin panel when I open the objects of such schemas. My quick hack around was that I'd have custom form fields. But with that, the above error occurs.

  config :kaffy,
  admin_title: "MyApp Admin",
  otp_app: :my_app,
  ecto_repo: MyApp.Repo,
  router: MyAppWeb.Router,
  #resources: &MyApp.Kaffy.Config.create_resources/1 <-- commented

@davidahmed
Copy link
Author

Tried this as well

Rename the BenchmarkAdmin module from MyApp.Kaffy.BenchmarkAdmin to MyApp.Benchmarks.BenchmarkAdmin

Unfortunately, the same issue persists.

@marvoh
Copy link

marvoh commented Jan 31, 2023

I have the same issue as well. When I remove the resources option, nothing loads, I get the following issue on all routes instead:

no match of right hand side value: :undefined.

image

@somoza
Copy link

somoza commented May 12, 2023

Worked fine commented the resources line as @davidahmed commented. Thanks!

@juantascon
Copy link

@davidahmed in create_resources() rename benchmarks to benchmark

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants