apache / apache/grails-core

noSelection attribute gets overridden when the field is not required

Open
#14,250 3 comments 0 reactions 0 assignees View on GitHub
relates-to: grails-fields
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

When we configure the noSelection parameter, it gets ignored by the tag when setting required to false. It's basically this line of code (that's everywhere in the FormFieldsTagLib.groovy):

`if (!model.required) attrs.noSelection = ["": ""]`

I, for one, see no functional connection between a value not being required, and the "noSelection" being ignored. The use case where you want to provide a "noSelection" param, in a non-required field, seems quite logical to me.

On the other hand, if the field is required, then this makes sense to override this to null. The `["": ""]` value actually ends up showing a blank option in select box, which again is something not so desirable. I'd request this overriding be removed entirely & let users have the control what they want to show there.

Contributor guide

Open the contributing guide

Research direction

Start in FormFieldsTagLib.groovy and inspect the repeated assignments that replace attrs.noSelection based on model.required. Confirm the intended behavior for required and non-required fields from the issue, then verify that configured noSelection values are preserved and unwanted blank options are not introduced.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy
Domain
frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.