Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

show enum as radio button in gsp

Tags:

grails

In my domain class, i have one enum:-

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

By generating default view, this shows as a dropdown in create.gsp page. My requirement is to show it as a radio group in create page from where i can select any one of the two values by clicking on radio button. can anyone provide some help. thnks

like image 307
A B Avatar asked Dec 27 '22 00:12

A B


1 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>

That should replace the current g:select in grails-app/views/product/_form.gsp

like image 129
tim_yates Avatar answered Jan 05 '23 16:01

tim_yates