|
Voted for this, and am attaching a patch which accomplishes pretty much the same thing as the previous commenter's code did. This was done against an SVN checkout - r6405.
Please consider adding this in, either with this patch directly or by similar code. It's a pretty easy thing to add, and will make using the g:select tag much more robust for lists. Not so easy because of
What would the side effects possibly be? This is functionality that's necessary when building HTML select elements with multiple elements preselected. I don't particularly care how it's accomplished, though I haven't seen any problems yet with the patch I submitted (not been in production use, but haven't seen any errors in my development yet).
I'm simply referring to the problem described in
<g:select from="[1, 2, 3, 4]" value="[2, 4]" /> you will see that you cannot simply do a toString() call on the key value since value is a list of numbers not a list of Strings. The current fix for Note that I have no objection to the requested functionality, I simply have concerns about how best to implement it Thanks Peter. I saw the 1250 issue and still didn't quite understand, given the fix that's in there. Yes, it might not work for all types. Having a toString() will probably fix the issue in almost all cases, however, and give people a defined way to deal with the issue for other types in a list.
I wasn't suggesting that you didn't want the functionality, but perhaps text only doesn't always get across the whole tone of a post. Thanks for the attention on this one! The fix for
Note, Alain's solution is actually better as the attached patch seems to just call contains on the value. If its meant to use String.contains that is a JDK 1.5 method
Ok so this is the tests I have passing now for this:
void testSimpleSelect() {
def template = '<g:select name="foo" from="[1,2,3]" value="1" />'
assertOutputEquals('''<select name="foo" id="foo" >
<option value="1" selected="selected" >1</option>
<option value="2" >2</option>
<option value="3" >3</option>
</select>''', template)
}
void testMultiSelect() {
def template = '<g:select name="foo" from="[1,2,3]" value="[2,3]" />'
assertOutputEquals('''<select name="foo" id="foo" multiple="true" >
<option value="1" >1</option>
<option value="2" selected="selected" >2</option>
<option value="3" selected="selected" >3</option>
</select>''', template)
}
Note you dont have to set multiple=true it just assumes that the case if the value is a collection (i don't see what else it could be other than a multi select in this case) |
|||||||||||||||||||||||||||||||||||||||||||||||
Correct (and nicer), version:
changed to