fields icon indicating copy to clipboard operation
fields copied to clipboard

noSelection attribute gets overridden when the field is not required

Open vijeetgv opened this issue 9 years ago • 3 comments

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.

vijeetgv avatar Mar 28 '16 18:03 vijeetgv

Had the same issue. Maybe we'll need to write a general template for association fields to get it fixed before we get any answer here :-( Does anyone already have one?

clessiomendes avatar Feb 20 '17 05:02 clessiomendes

Seems this issue is still open and I'm unable to conceive of a workaround.

In my case, it's not an association that's causing me problems, it's rather an inList constraint.

Basically what I want is the equivalent to the placeholder="" in the <input> tag, but for a <select>. It seems to me that this is what the "noSelection" is for.

Maaaaaaaaaaaybe the solution could be to write a new version of <g:select> that uses the placeholder="" to override the empty field in the tag generated by <f:widget>...

monetschemist avatar Jul 27 '22 19:07 monetschemist

Actually it occurs to me that it might be better to make this kind of modification to <f:widget>, either so that it has a noSelection attribute or a placeholder attribute.

monetschemist avatar Jul 27 '22 21:07 monetschemist