wdtnh

wdtnh

Desperate to get this parent lookup working in simple form .input type=select

I have a phoenix app with a lot of related tables. In particular, I have a regions (think territory) as a parent table that has a related child table consisting of 3-digit zip codes that are in a table region_zips.
I need a select form element in the region_zip form (created by phx.gen.html) in order to make sure I’m picking the correct region for a particular 3 digit zip code. I cannot get this to work no matter how many ways I’ve tried. I know the lookup in def new(conn, _params) works. It’s just not working in the form. I would greatly appreciate any assistance. Thanks in advance. Bill

def new(conn, _params) do
    regions = Regions.lookup_regions() #  Valid results are [%{id: 1, name: "Test" },...]
    changeset = RegionZips.change_region_zip(%RegionZip{})
    render(conn, :new, changeset: changeset, regions: regions)
  end

The related form is

<.simple_form :let={f} for={@changeset} action={@action}>
  <.error :if={@changeset.action}>
    Oops, something went wrong! Please check the errors below.
  </.error>
  <.input field={f[:region_id]} type="select" options={@regions} label="Region" />
  <.input field={f[:zip_prefix]} type="text" label="Zip prefix" />
  <:actions>
    <.button>Save Region zip</.button>
  </:actions>
</.simple_form>

First Post!

wdtnh

wdtnh

Appreciate the reply but that wasn’t it. I’ve formatted the regions lookup in a number of ways as an array of maps, tuples, keywords, i, etc. I still get key error message that lookup of regions passed as an arg to the render function executes.

KeyError at GET /region_zips/new
key :regions not found in: %{
  action: "/region_zips",
  __given__: %{
    action: "/region_zips",
    __changed__: nil,
    changeset: #Ecto.Changeset<
      action: nil,
      changes: %{},
      errors: [
        region_id: {"can't be blank", [validation: :required]},
        zip_prefix: {"can't be blank", [validation: :required]}
      ],
      data: #Crm.RegionZips.RegionZip<>,
      valid?: false,
      ...
    >
  }, 

Last Post!

wdtnh

wdtnh

I’ve been traveling & haven’t had time to dig into this but I believe you hit the nail on the head of what my problem was. I absolutely love Elixir but sometimes I get lost how things get passed along. In the related region_zips VIEW field, I will pass regions as an attribute which I failed to do. I see where I was previously passing in as an action. I’ve already corrected for the proper formatting of the options in terms of key and value pairs. Thanks for the assist it is greatly appreciated.

Where Next?

Popular in Questions Top

vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New

Other popular topics Top

grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 54006 488
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31494 112
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

We're in Beta

About us Mission Statement