Problem filling in screen fields

I needed to make a select in the database …
that would fill all other automatic fields …
The only way I can do is to select one at a time …

Can anybody help me??

Ex:

Name:
Last name:
City:
State:

By filling in the field name …
All other fields fill in automatically.

Current Template
select 1
<%= select(f, :cidade_app, @cidade_all, class: "custom-select") %>

select 2
<%= select(f, :estado_app, @estado_all, class: "custom-select") %>

Controller

cidade_all: Repo.all(from(c in Cidade, select: {c.cidade_cidade, c.cidade_cidade})),
estado_all: Repo.all(from(c in Cidade, distinct: true, select: {c.estado_cidade, c.estado_cidade})))

I know in this part it would be nice to use javascript …
Could give me some ex?

Instead of doing this, you can query the database as usual and transform the result “manually”

Repo.all(from(c in Cidade, select: c.cidade_cidade})) |> Enum.map(fn cidade_cidade -> {cidade_cidade, cidade_cidade} end)

or, if using macros for query building instead of keywords:

Cidade
|> select([:cidade_cidade])
|> Repo.all()
|> Enum.map(fn cidade_cidade ->
  {cidade_cidade, cidade_cidade}
end)

As for the rest, what do you expect your html to look like and what do you currently get?

1 Like

As you can see in the image …
Currently I have in my html, that way …

Brasilia > DF
Goiania > GO

Note: The form I am using today is being manual.
I needed it to update automatically.

cidade

Template Form

<%= select(f, :cidade_app, @cidade_all, class: “custom-select”) %>
<%= error_tag f, :cidade_app %>

<%= select(f, :estado_app, @estado_all, class: “custom-select”) %>
<%= error_tag f, :estado_app %>

You can probably render {cidade, estado} pairs into a <script> tag and synchronize them with js on the client.