Automatic field update

I currently have an application that runs 2 select.
Select 1 = Repo.all (from (c in Client, select: {c.fantasia_cliente, c.cod_cliente}, order_by: [c.fantasia_cliente]))

Select 2 = Repo.all (from (c in Client, select: {c.client_type, c.client_type, where: c.cod_client == ^ client_client))

it works perfectly.

I need the Select 2, automatic update …
As soon as select 1 modifies

Is there a way?

form.html
Select 1
<%= select(f, :cliente_pedidos, @cod_cliente, class: "form-control") %>
Select2
<%= select(f, :tipocli_pedidos, @tipo_cliente, class: "form-control") %>

Updating selects in your html is usually a javascript task, but you might want to look into Drab if you’re not as comfortable in that space.

1 Like

intercoolerjs actually provides an example that does exactly what you’re asking for

2 Likes

The problem I’m having is …
Select 2 only recognizes the first line of select 1 …
Type…

Result of select 1 = Brings all the results of a column
Result of select 2 = You are only returning the result of the first row of select 1 …

I made some adjustments, but to no avail …

select 1: cod_cliente = Repo.all(from(c in Cliente, select: {c.fantasia_cliente, c.cod_cliente}, order_by: [c.fantasia_cliente]))

select 2: tipo_cliente = Repo.all(from(c in Cliente, select: c.tipo_cliente, where: c.cod_cliente == ^elem(List.first(cod_cliente),1))) |> List.first()

In my form.html …
I’m asking him to get select 2 and update the field …
More like always, only the result of the first line of select 1 returns me

How should it be?
In javascript, it will return me the full 1 select tbm! …
I know I can not, escape from javascript …
But I’m starting to think my query is wrong.