I would like to make a select box using <g:select/>
that translates to this html:
<select id="myselect" name="myselect">
<option value="r">RED</option>
<option value="g">GREEN</option>
<option value="b">BLUE</option>
</select>
I would also like the value to be preselected from a bean when the page reloads.
I'm doing this inside a so I have a table with each row having a separate option box.
I'm currently accomplishing this in the below html:
<g:each in=${mylist} status="i" var="myInst">
<select id="status${myInst}" name="status${myInst}" data-id="${myInst.id}">
<option value="r" <g:if test="${myInst.color == "r"}">selected</g:if>>RED</option>
<option value="g" <g:if test="${myInst.color == "g"}">selected</g:if>>Green</option>
<option value="b" <g:if test="${myInst.color == "b"}">selected</g:if>>BLUE</option>
</select>
</g:each>
This all works fine but I'd like to change that ugly <select>
into <g:select>
<g:select id="myselect" name="myselect" value="${myInst.color}"
from="${['r': 'RED', 'g': 'GREEN', 'b': 'BLUE']}"
optionKey="key" optionValue="value" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With