From aa880f98c3f67622b7fa1e53f963aa64b6cc6b0b Mon Sep 17 00:00:00 2001 From: Scott Murphy Heiberg Date: Wed, 6 Nov 2024 22:32:38 -0500 Subject: [PATCH] Fix for invalid class not rendering on widget --- .../plugin/formfields/FormFieldsTagLib.groovy | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/grails-app/taglib/grails/plugin/formfields/FormFieldsTagLib.groovy b/grails-app/taglib/grails/plugin/formfields/FormFieldsTagLib.groovy index b33bb07b..d24393fe 100644 --- a/grails-app/taglib/grails/plugin/formfields/FormFieldsTagLib.groovy +++ b/grails-app/taglib/grails/plugin/formfields/FormFieldsTagLib.groovy @@ -202,10 +202,16 @@ class FormFieldsTagLib { } } - List classes = [widgetAttrs['class'] ?: ''] - if (model.invalid) classes << (widgetAttrs.remove('invalidClass') ?: '') - if (model.required) classes << (widgetAttrs.remove('requiredClass') ?: '') - widgetAttrs['class'] = classes.join(' ').trim() + List widgetClasses = [widgetAttrs['class'] ?: ''] + String cssClass = widgetAttrs.remove('invalidClass') + if (cssClass && model.invalid) { + widgetClasses << cssClass + } + cssClass = widgetAttrs.remove('requiredClass') + if (cssClass && model.required) { + widgetClasses << cssClass + } + widgetAttrs['class'] = widgetClasses.join(' ').trim() if (widgetAttrs['class'].isEmpty()) { widgetAttrs.remove('class') }