From 1d1bbaf487700d3b4fea29a2f720a3162a3f2fbd Mon Sep 17 00:00:00 2001 From: Scott Murphy Heiberg Date: Sun, 12 Jan 2025 11:39:05 -0800 Subject: [PATCH 1/3] LocalDate and LocalDateTime support --- .../grails/plugin/formfields/FormFieldsTagLib.groovy | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/grails-app/taglib/grails/plugin/formfields/FormFieldsTagLib.groovy b/grails-app/taglib/grails/plugin/formfields/FormFieldsTagLib.groovy index 9571ab93..c257a3c9 100644 --- a/grails-app/taglib/grails/plugin/formfields/FormFieldsTagLib.groovy +++ b/grails-app/taglib/grails/plugin/formfields/FormFieldsTagLib.groovy @@ -42,6 +42,8 @@ import org.springframework.web.servlet.LocaleResolver import jakarta.servlet.http.HttpServletRequest import java.sql.Blob import java.text.NumberFormat +import java.time.LocalDate +import java.time.LocalDateTime import static FormFieldsTemplateService.toPropertyNameFormat @@ -712,7 +714,7 @@ class FormFieldsTagLib { return renderAssociationInput(model, attrs) } else if (oneToMany) { return renderOneToManyInput(model, attrs) - } else if (model.type in [Date, Calendar, java.sql.Date, java.sql.Time]) { + } else if (model.type in [Date, Calendar, java.sql.Date, java.sql.Time, LocalDate, LocalDateTime]) { return renderDateTimeInput(model, attrs) } else if (model.type in [byte[], Byte[], Blob]) { return g.field(attrs + [type: "file"]) @@ -726,7 +728,7 @@ class FormFieldsTagLib { CharSequence renderDateTimeInput(Map model, Map attrs) { - attrs.precision = model.type == java.sql.Time ? "minute" : "day" + attrs.precision = (model.type == java.sql.Time || java.time.LocalDate)? "minute" : "day" if (!model.required) { attrs.noSelection = ["": ""] attrs.default = "none" @@ -915,6 +917,8 @@ class FormFieldsTagLib { case Date: case java.sql.Date: case java.sql.Time: + case LocalDate: + case LocalDateTime: g.formatDate(date: model.value) break default: From 1dbe3dacfeb2d5345be0a95c7b3acb11d055705d Mon Sep 17 00:00:00 2001 From: Scott Murphy Heiberg Date: Sun, 12 Jan 2025 11:53:14 -0800 Subject: [PATCH 2/3] Fix precision --- .../taglib/grails/plugin/formfields/FormFieldsTagLib.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grails-app/taglib/grails/plugin/formfields/FormFieldsTagLib.groovy b/grails-app/taglib/grails/plugin/formfields/FormFieldsTagLib.groovy index c257a3c9..aeb8cf8d 100644 --- a/grails-app/taglib/grails/plugin/formfields/FormFieldsTagLib.groovy +++ b/grails-app/taglib/grails/plugin/formfields/FormFieldsTagLib.groovy @@ -728,7 +728,7 @@ class FormFieldsTagLib { CharSequence renderDateTimeInput(Map model, Map attrs) { - attrs.precision = (model.type == java.sql.Time || java.time.LocalDate)? "minute" : "day" + attrs.precision = model.type in [java.sql.Time, LocalDateTime]? "minute" : "day" if (!model.required) { attrs.noSelection = ["": ""] attrs.default = "none" From 67b5e07c11a8987fbb211429d527cd42b8d6ac5b Mon Sep 17 00:00:00 2001 From: Scott Murphy Heiberg Date: Sun, 12 Jan 2025 11:57:15 -0800 Subject: [PATCH 3/3] update tests --- .../formfields/DefaultInputRenderingSpec.groovy | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/test/groovy/grails/plugin/formfields/DefaultInputRenderingSpec.groovy b/src/test/groovy/grails/plugin/formfields/DefaultInputRenderingSpec.groovy index 7c2fce0e..2c616335 100644 --- a/src/test/groovy/grails/plugin/formfields/DefaultInputRenderingSpec.groovy +++ b/src/test/groovy/grails/plugin/formfields/DefaultInputRenderingSpec.groovy @@ -21,6 +21,8 @@ import spock.lang.Shared import spock.lang.Unroll import java.sql.Blob +import java.time.LocalDate +import java.time.LocalDateTime @Unroll class DefaultInputRenderingSpec extends AbstractFormFieldsTagLibSpec implements TagLibUnitTest { @@ -248,6 +250,8 @@ class DefaultInputRenderingSpec extends AbstractFormFieldsTagLibSpec implements Calendar | /select name="prop_day"/ java.sql.Date | /select name="prop_day"/ java.sql.Time | /select name="prop_day"/ + LocalDate | /select name="prop_day"/ + LocalDateTime | /select name="prop_day"/ TimeZone | /