8

I'm struggling arround with the g:radioGroup tag -- I want to create some radios and some labels correspondig to the radios:

<g:radioGroup name="stateOfHealth" value="${review.stateOfHealth}" id="stammp"
        labels="['1','2','3','4','5']"
        values="['bad','suboptimal','well','veryWell','excellent']">
    <span class="radioSpan"> ${it.radio}</span>
    <label for="${ ???? }">${it.label}</label>
</g:radioGroup>

What do I need to do to insert in the label's "for" attribute to match the right radio?

Elias Dorneles
  • 22,556
  • 11
  • 85
  • 107
john Smith
  • 17,409
  • 11
  • 76
  • 117

1 Answers1

9

You don't need to set the for attribute, just wrap the radio with the label, like this:

<g:radioGroup name="stateOfHealth" value="${review.stateOfHealth}" id="stammp"
        labels="['1','2','3','4','5']"
        values="['bad','suboptimal','well','veryWell','excellent']">

    <label>
            <span class="radioSpan">${it.radio}</span>
            ${it.label}
    </label>

</g:radioGroup>
Elias Dorneles
  • 22,556
  • 11
  • 85
  • 107
  • this just renders the label text in no tags this is how i came to this question – john Smith Apr 21 '13 at 21:12
  • No, in this case the `label` tag is wrapping the radio, so you don't need to set the `for` attribute. If you try, you'll see that when you click a label the appropriate radio box will check. – Elias Dorneles Apr 22 '13 at 12:01
  • haha sorryy i didn´t realized your label tags, thanks a lot this woorks awesome – john Smith Apr 22 '13 at 17:45