Thank you so much for your really in-depth answer. You are right it’s an ecto struct and your ways of doing this maybe could work but I think it’s over-complicating it. Your answer is helping me understand what is going on better which is invaluable. I’ve changed tack a little since my initial post and I think I can achieve what I want using just HEEX functions and CSS.
I’m not a frontend dev and I’m completely new to HTML/CSS/JS in terms of actually coding but needs must whilst we are hiring a new front end team member.
I am trying to have three (dynamic from a list) cards that act as radio inputs for a form. The tailwind playground I have copied below is a simplified version of what I am trying to achieve.
In terms of what this looks like using HEEX.
<li>
<%= radio_button(:payment, :investment_id, 1 , class: "sr-only peer") %>
<%= label(:payment, :investment_id_1, "Investment 1" , class: "flex p-5 bg-white border border-gray-300 rounded-lg cursor-pointer focus:outline-none hover:bg-gray-50 peer-checked:ring-green-500 peer-checked:ring-2 peer-checked:border-transparent") %>
<div class="hidden w-5 h-5 peer-checked:block top-5 right-3">
1
</div>
</li>
<li>
<%= radio_button(:payment, :investment_id, 2 , class: "sr-only peer") %>
<%= label(:payment, :investment_id_2, "Investment 2" , class: "flex p-5 bg-white border border-gray-300 rounded-lg cursor-pointer focus:outline-none hover:bg-gray-50 peer-checked:ring-green-500 peer-checked:ring-2 peer-checked:border-transparent") %>
<div class="hidden w-5 h-5 peer-checked:block top-5 right-3">
2
</div>
</li>
As you can see, I had to hardcode the radio input value, Label name and also the label field (this is to make sure the label-for value matches the radio input.)
I feel like I am part of the way there but in my head - I should be able to combine this with
<%= for investment <- @investments do %>
<% end %>
and not hardcode so many parts of the form, especially the value and label.
I haven’t even begun to think about how I can add content to each card beyond just the label but that’s another bridge I need to cross.