Show listing as switch in gsp

In my domain class, I have one enumeration: -

class Product{
  Type type
  enum Type{
    MEDICINE, NON_MEDICINE
  }
}

When creating a default view, it appears as a drop-down list on the create.gsp page. My requirement is to show it as a radio group in page creation, from where I can select either of the two values ​​by clicking on the switch. can anyone help. thnks

+3
source share
2 answers

This should work:

<g:radioGroup name="type"
                  values="${test.Product$Type?.values()}"
                  labels="${test.Product$Type.values()*.name()}"
                  value="${productInstance?.type?.name()}">
  ${it.radio} <g:message code="${it.label}" />&nbsp;
</g:radioGroup>

This should replace the current one g:selectingrails-app/views/product/_form.gsp

+8
source

Try

<g:radioGroup name="type" values="${['MEDICINE', 'NON_MEDICINE']}" value="${currentInstance.type}" labels="${['Medicine', 'Non medicine']}">
<span>${it.label} - ${it.radio}</span>
</g:radioGroup>
+1
source

All Articles