Reputation: 149
I'm a newbie to Grails and GSPs.
I need to achieve the following code using g:select tag
<select name="applaiances" style="width: 200px" onchange="selectedTC(this); ">
<g:each in="${applaianceList}" var="appl">
<g:if test="${appl == "TELEVISION"}">
<option value="TELEVISION">TV</option>
</g:if>
<g:else>
<option value="${appl}">${appl}</option>
</g:else>
</g:each>
</select>
Any help would be appreciated.
Upvotes: 0
Views: 1686
Reputation: 2512
Haven't tried this in an app but you could try something like:
<g:select name="applaiances" onchange="selectedTC(this);" from="${applaianceList}" optionKey="${{it=='TELEVISION'?'TELEVISION':it}}" optionValue="${{it=='TELEVISION'?'TV':it}}"></g:select>
Not sure about the optionKey but you can apply transformation via a closure on the optionValue.
Update: This is documented here. Just search for the phrase "If you require even more control over how each"
Upvotes: 2