monal86
monal86

Reputation: 463

grails Radio Button True or false checked property

I have radio group with two values. On editing a record, the radio should be set to checked or unchecked depending on the value from database.I use

    <input type="radio" name="value1" value="${someValue}" ${it.id == true ?'checked="checked"' : ''}>                         
     <input type="radio" name="value1" value="${someValue}" ${it.id == false ? 'checked="checked"' : ''}> 

Using such code, gives me syntax error. Please correct my syntax.

Upvotes: 0

Views: 3042

Answers (2)

dmahapatro
dmahapatro

Reputation: 50285

Looks like you have to go this lengthy way. (assuming it.id yields a boolean)

<g:if test="${it.id}"> 
    <g:radio name="value1" value="${someValue}" checked="${it.id}" />
</g:if>
<g:else>
    <g:radio name="value1" value="${someValue}" />
</g:else>

You can use html input instead of g:radio in this case as well.

Upvotes: 1

tim_yates
tim_yates

Reputation: 171184

Can't you use:

<g:radio name="value1" value="${someValue}" checked="${it.id}" />

(assuming it.id is a boolean as you seem to say)

Upvotes: 3

Related Questions