ycv005

ycv005

Jump to Particular Index in for loop Phoenix HTML?

How to look out for particular value in the For loop of the Phoenix HTML.
Like I only want to fetch out the 2nd candidate_pipeline from the @candidate_pipelines. How to do that? Your response will be highly appreciable. Note- Inside my for loop, the variable are depended on candidate_pipeline.

              <%= for candidate_pipeline <- @candidate_pipelines do %>
          
                <%= form_for get_candidate_update_changeset(candidate_pipeline), "#", [class: "d-inline", phx_change: "update_candidate_stage"], fn f -> %>
                  <input type="hidden" value="<%= candidate_pipeline.id %>" name="candidate_id"/>
                  <%= select f, :job_stage_id, Enum.map(@job_stages, &{&1.name, &1.id}), [class: "custom-select custom-select-sm"] %>
                <% end %>
              <% end %> 

Most Liked

peerreynders

peerreynders

Get rid of the for comprehension and define a function in the view to do the work

<%= form_for second_changeset(@candidate_pipelines), "#", [class: "d-inline", phx_change: "update_candidate_stage"], fn f -> %>
  <input type="hidden" value="<%= candidate_pipeline.id %>" name="candidate_id"/>
  <%= select f, :job_stage_id, Enum.map(@job_stages, &{&1.name, &1.id}), [class: "custom-select custom-select-sm"] %>
<% end %>

For example you can pick the second element in a list this way:

iex(1)> second = fn [_, value| _] -> value end
#Function<6.128620087/1 in :erl_eval.expr/5>
iex(2)> list = [1,2,3]
[1, 2, 3]
iex(3)> second.(list)
2
iex(4)>

Example of defining view functions (page_view.ex) being used in index.html.eex

Where Next?

Popular in Questions Top

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
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
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
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a &gt; b) do {:ok, "a"} end if (a &lt; b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
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
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: The documentation above suggests that while ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New

Other popular topics Top

AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
Qqwy
Update: How to use the Blogs &amp; Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 126479 1222
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New

We're in Beta

About us Mission Statement