Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we have more than one field in g:select optionValue?

Tags:

grails

Is there any way to show more than one field name in optionValue?

<g:select name="id" from="${Books.list()}" optionKey="id"
          value="" optionValue="name"
          noSelection="${['null':'Select Publisher...']}"/>

Expe:

<g:select name="id" from="${Books.list()}" optionKey="id"
          value="" optionValue="name and author"
          noSelection="${['null':'Select Publisher...']}"/>
like image 481
Honey Avatar asked Nov 19 '10 05:11

Honey


1 Answers

You can pass a closure for your option value if you don't want to modify your domain class:

<g:select name="id" from="${Books.list()}" optionKey="id"
          value="" optionValue="${{it.name +' '+it.author}}"
          noSelection="${['null':'Select Publisher...']}"/>
like image 98
Reverend Gonzo Avatar answered Sep 28 '22 05:09

Reverend Gonzo