grails g:select tag

匿名 (未验证) 提交于 2019-12-03 08:48:34

问题:

I am using a g:select tag like this:

<td><g:select name="newCity"         id="${'newCity_' +cityData.uid}"         from="${cityData.name}"         value="${cityData.someValue}"         noSelection="${['null':'Select City...']}" class="newCity" /> </td> 

which renders the following HTML:

<td> <select name="newCity" id="newCity_abc" class="newCity" > <option value="null">Select City...</option> <option value="A" >A</option> <option value="B" >B</option> <option value="C" >C-</option> <option value="D" >D</option> </select> </td>  

However, I want my HTML to look like this; with class inserted since I am doing some javascript validation:

<td> <select name="newCity" id="newCity_abc" class="newCity" > <option value="null">Select City...</option> <option value="A" class="populated" >A</option> <option value="B" class="notpopulated" >B</option> <option value="C" class="populated" >C</option> <option value="D" class="notpopulated" >D</option> </select> </td> 

Is this possible?

Do I need to create a custom tag library to acheive this?

Any help will be appreciated, Thanks!

回答1:

I don't believe this is possible. The select tag implementation (which writes out the <option> tags) calls the private method writeValueAndCheckIfSelected to fill in the option, and this is not aware of any class names.

There is a 2 year old New Feature Request on the Grails JIRA, but I think you may be stuck rolling your own tag to do this for your specific situation.



文章来源: grails g:select tag
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!