Reputation: 534
How to i set the default value on g:select
from controller? From my list of name's for example
here's my list ["peter","josh","john","thomas"]
render g.select( name:'selectName',
from:listOfName,
optionKey:'id',
optionValue:'name',
value:'john')
after submitting the form when the g:select reload it's still set on the first list which is peter. i don't know how do i get the default value for selection, or how do i get the the value on onComplete tags of g:select
Upvotes: 0
Views: 925
Reputation: 24776
Looking at your example the reason why it's selecting the first value in the list is because your optionKey is that of "id" and your "value" appears to be the optionValue. The "value" should contain the "id" of the selected option not the optionValue.
Here is an example to illustrate this:
<g:select name="selectName" from="${[['id': 2, 'name': 'Bob'], ['id': 1, 'name': 'Joe']]}" optionKey="id" optionValue="name" value="1" />
UPDATE (Since you added more information to your question and changed it)
The optionKey and optionValue settings of your select are not needed. In your new example simple use this:
render g.select( name:'selectName',
from:listOfName,
value:'john')
Upvotes: 1