Question

How do I use the validation constraints I have in the domain model automatically in the <g:select/> tag of my view, or is this not possible?

In my domain class, I have an int property with a size constraint:

int texture
static constraints = {
  texture range:0..8
}

Now, in my view I want to use a select to allow the user to choose the proper value. I currently have this:

<g:form action="save">
  <div class="fieldcontain  ">
        <label for="foamScore.texture">
            Foam Texture

        </label>
        <g:select name="foamScore.texture" from="${0..8}"/>
    </div>
</g:form>

I would like to avoid repeating the 0..8 part in the view if possible.

Was it helpful?

Solution

Grails jquery-validation-ui plugin will perform client side validation using server side GORM constraints. This way you can avoid duplicating the validation logic on the client side. Here is the link to the plugin http://grails.org/plugin/jquery-validation-ui

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top