Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

grails g:select tag

Tags:

grails

groovy

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!

like image 309
frank.C Avatar asked Oct 12 '22 01:10

frank.C


1 Answers

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.

like image 111
tim_yates Avatar answered Nov 17 '22 01:11

tim_yates