开发者

grails g:select tag

开发者 https://www.devze.com 2023-03-05 21:47 出处:网络
I am using a g:select tag like this: <td><g:select name=\"newCity\" id=\"${\'newCity_\' +cityData.uid}\"

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!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消