gilbertosj

gilbertosj

How to auto-fill fields based on info in others?

I need to fill in all the fields, based on information in another one automatically …
Ex: Through the “Customer Code” fill in the automatic “Customer Type” …

What should I do ??

Current Controller

  def new (conn, _params)
    changeset = Account.change_order (% Order {})
    cod_client = Repo.all (from (c in Client, select: {c.fantasia_cliente, c.cod_client}))
    client_type = Repo.all (from (c in Client, select: {c.client_type, c.client_type}))

     render (conn, "new.html", changeset: changeset,
      condemnation, condemnation,
      sales_codes: sales_codes,
      customer_code: customer_code,
      client_type: client_type)
  end

Current Template

  <div class = "form-group">
    <label> Client Type
     <div class = "input-group">
    <span class = "input-group-addon" id = "basic-addon1"> <i class = "fa fa-angle-double-down" aria-hidden = "true"> </ i>
    <% = select (f, :client_questions, @cod_client)%>
    </ div>
    <% = error_tag f, :client_questions %>
    </ label>
  </ div>

  <div class = "form-group">
    <label> Client Type
     <div class = "input-group">
    <span class = "input-group-addon" id = "basic-addon1"> <i class = "fa fa-angle-double-down" aria-hidden = "true"> </ i>
    <% = select (f, :tipocli_pedidos, @client_type)%>
    </ div>
    <% = error_tag f, :tipocli_pedidos %>
    </ label>
  </ div>

First Post!

kokolegorille

kokolegorille

The problem You describe is related to frontend.

In frontend, JS can help You get a little bit reactive. Such as reacting to change events.

the link between code and type is not really clear, it could be having a lot of possibilities, to something that is limited. eg. select country from country_code.

In case of limited set, it might be better to load full data to client. This allow reactive change without data call.

If it is too costly to send all data, You would need to do ajax call, fetch call or websocket call, This way You will receive data from server, and You will incorporate those data with DOM manipulation.

Your solution lies in JS, or Drab :slight_smile:

Some possibilities…

  • jquery
  • unpoly
  • a larger framework (React, Angular, Ember, Elm etc.)

But if You want to keep it simple, You can try with Vanilla JS.

Where Next?

Popular in Questions Top

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call t...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
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

Other popular topics Top

siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
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 31194 112
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31307 143
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
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
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
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54250 245
New

We're in Beta

About us Mission Statement