So I have this tagLib;
def trimTo = { attrs, body ->
int length = attrs.int('length')
String text = body()
if (text.size() > length) {
text = text.substring(0, length - 1) + '...'
}
out << text
}
Normally I'm using it like this;
<g:trimTo length="50">${fieldValue(bean: fooInstance, field: "textEng")}</g:trimTo>
And all is good.
But I want to call it in a g:select tag that looks like;
<g:select name="phrases" from="${Foo.list()}" optionValue="${{it.textEng}}" multiple="multiple" optionKey="id" size="25" value="${fooParentInstance?.children*.id}" class="many-to-many"/>
Specifically I would like to use it to shorten what is being displayed by the optionValue attribute, the results of {it.textEng}.
I have tried several different combinations can can't seem figure out the correct syntax.
Thanks in advance for any assistance.
*edited for spelling
Managed to figure it, mostly through trial and error with a tiny bit of reading and reasoning tossed in for good measure.
optionValue="${{g.trimTo([length: 50], it.textEng)}}"
Thanks all,