Phoenix.HTML label for radio button

Hey there,

using Phoenix.HTML I can create radio buttons easily:

<%= radio_button f, :gender, "male" %>
# <input id="user_gender_male" name="user[gender]" type="radio" value="male">

However, I can’t find a way to create a label with user_gender_male:

<%= label f, :gender, "Male" %>
# <label for="user_gender">Male</label>

<%= label :gender, :male, "Male" %>
# <label for="gender_male">Male</label>

Is there a way to specify all three, form, field and value?

Thanks!

Edit: Found a way, but it’s not nice. Isn’t there a better solution?

<%= label f, :gender_male, "Male" %>
# <label for="user_gender_male">Male</label>

What do you mean by not nice? :slight_smile: Or you need to do as above or put the checkbox inside the label.

1 Like

I had to write a little helper function to construct it based on field and value. Just wanted to know if there’s a better way, thanks!