Search code examples
grailsgsp

View hidden fields in the gsp code via if-operator in Grails


I am writing a form. If checkbox in this form is filled, some hidden fields in this form must be shown. This is a part of my form:

<div class="checkbox">
  <label><g:checkBox name="isAdminCafee" value="${false}"/>Register as admin</label>
</div>
<g:if test="${isAdminCafee == true}">
  some admin data
</g:if>

I've decided to use if-operator for solving this task, but when I set check-box on, hidden fields don't show. How to fix it?


Solution

  • It seems you are trying to show some admin data when user checks the checkbox and hide some admin data when user unchecks the checkbox.

    You have used g:if tag library which is interpreted in the server and render the part inside it if the test condition is true.

    Instead of using g:if tag library, you need to hide some admin data using css and use javascript to show or hide when user checks or unchecks the checkbox.