Question

Grails 2.1
Fields plugin 1.3

I'm trying to figure out how to customize the field rendering of Dates so that will include the constraints (attributes) defined in the domain class.

Based on the Fields plugin documentation and other information I have found, I should be able to do this through a default _input.gsp for Dates.
grails-app/views/_fields/date/_input.gsp

Currently the constraints are not being taken into account with the Fields plugin. The following results in a date field with years beginning with 1912 through 2112: birthDate( attributes: ["precision" : "day", "years" : 2016..1970])

This one results in a date field for Year, Month and Day even though the precision has been set to month and again, I get years 1912-2112: expireDate(attributes: ["precision" : "month", "years" : 2007..2016])

How do I setup the _input.gsp to use the constraints for the datePicker?

Was it helpful?

Solution

I was able to figure out a solution, it may not be the best solution, but it is working for my app.

Using grails-app/views/_fields/date/_input.gsp

<%@ page defaultCodec="html" %>

<g:if test="${constraints.nullable == true}">
    <g:datePicker name="${property}" value="${value}" precision="${constraints.attributes.precision}" years="${constraints.attributes.years}" default="none" noSelection="['': '']" />
</g:if>
<g:else>
<g:datePicker name="${property}" value="${value}" precision="${constraints.attributes.precision}" years="${constraints.attributes.years}"/>
</g:else>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top