I having a grails element
<g:select name="name" from="${list}" optionKey='code' optionValue='name' ></g:select>
where the optionValue contains some HTML elements like this,
I want to show only the country name, already I tried using encodeAsHTML(), but no idea how to use. Please suggest.
Thanks
you can not do this with the out-of-box g.select
tag. you need to iterate through your list manually:
<select name="someName">
<option value="">- no select -</option>
<g:each in="${list}" var="c">
<option value="${c.code}">${c.name.replaceFirst( /<span class='countryName'>([\w\s]+)</span>/, '$1' )}</option>
</g:each>
</select>
This is happening because of XSS . Instead of encodeAsHTML
use raw
. Try this:
<g:select name="name" from="${list.collect { raw(it) }}" optionKey='code' optionValue='name'/>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.