wdtnh
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>
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex










Showing Posts 1 to 4- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
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.
jdiago
Take a look at the implementation of
category_opts/1in this guide. It’s the same as what you’re trying to do.edit: also, the reason why
@regionsisn’t found in the form assigns is because it has to be passed in when the form is rendered innew.html.heex. Your@regionsassign exists for the new action not the form, which is a function component. There should be a line like this where you’ll have to addregionsas an attr for the form.wdtnh
Thanks. I’ll check it out and reply back when I get a chance to work on it.
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.