Home g:select disabled property doesn't work properly
Reply: 0

g:select disabled property doesn't work properly

user2010
1#
user2010 Published in April 22, 2018, 10:05 pm

In my .gsp I have a dropdown select option.

<g:select id="id"
          name="name"
          disabled="${model.x == MyEnum.X}"   //<--- note here
          from="${MyEnum.values()}"
          optionValue="naturalName"
          noSelection="['': '']"
          value="${model?.x}"/>

The generated .html of this portion looks like this -

<select id="id" name="name" > //n <--- note here
    <option value=""></option>
    <option value="A" >A</option>
</select>

*note: the disabled property is not generated!

BUT if I put the logic and value of disabled property inside a variable first -

<g:if test="${model.x == MyEnum.X}">
    <g:set var="disabled" value="true"/>
</g:if>

Then, use the variable inside disabled property -

<g:select id="id"
          name="name"
          disabled="${disabled}"     //<------here
          from="${MyEnum.values()}"
          optionValue="naturalName"
          noSelection="['': '']"
          value="${model?.x}"/>

It works as expected! I mean, generates disabled="disabled" at generated .html file -

<select id="id" name="name" disabled="disabled"> //n <--- here
    <option value=""></option>
    <option value="A" >A</option>
</select>

Can someone explain this inconsistent behavior why .gsp can not process 1'st approach but the 2'nd

I said inconsistent because on both approach I did the same boolean checking but .gsp works accurately on the second approach.

FYI: my grails version is 2.4.4

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.557779 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO