Grails RadioGroup, how to bind labels to radio name
Asked Answered
H

1

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?

Hermaherman answered 20/4, 2013 at 15:31 Comment(0)
C
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>
Continuo answered 21/4, 2013 at 14:9 Comment(3)
this just renders the label text in no tags this is how i came to this questionHermaherman
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.Continuo
haha sorryy i didn´t realized your label tags, thanks a lot this woorks awesomeHermaherman

© 2022 - 2024 — McMap. All rights reserved.