[英]Grails countrySelect tag - default value
This is my code 这是我的代码
<g:countrySelect name="country" value="${customerInstance?.country}"
noSelection="['':'-Choose your country-']"/>
In show view(page) It displays the value, instead of that i want it to display the selected option 在show view(page)中显示值,而不是我希望它显示选定的选项
for example, -Choose your country- Afghanistan Albania here in above example i want the show page to display option ("Afghanistan") instead of that value ("alg"), this is my question help me out of this problem 例如,-选择您的国家-阿富汗在上面的示例中,我希望显示页面显示选项(“ Afghanistan”)而不是该值(“ alg”),这是我的问题帮助我解决了这个问题
You have to override the countrySelect tag or create your own. 您必须覆盖countrySelect标记或创建自己的标记。
import org.codehaus.groovy.grails.plugins.web.taglib.CountryTagLib
class FormsTagLib {
static namespace = "bootstrap"
Closure countrySelect = { attrs ->
if (!attrs.from) {
attrs.from = CountryTagLib.COUNTRY_CODES_BY_NAME_ORDER
}
if (!attrs['valueMessagePrefix']) attrs.optionValue = { CountryTagLib.ISO3166_3[it] }
attrs.optionKey = { CountryTagLib.ISO3166_3[it] }
if (!attrs.value) {
attrs.value = attrs.remove('default')
}
out << select(attrs)
}
}
and call it as 并称其为
<bootstrap:countrySelect name="country" value="${customerInstance?.country}" noSelection="['':'-Choose your country-']"/>
Try this..,. 尝试这个..,。
You can override optionKey of tag. 您可以覆盖标签的optionKey。
eg 例如
g:countrySelect name="country" noSelection="['':'-Choose your country-']" value="${customerInstance?.country}" optionKey="${{CountryTagLib.ISO3166_3[it]}}"
Now the optionKey and optionValue will be the full country name. 现在optionKey和optionValue将是完整的国家名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.