I noticed that some of the Grails tags for generating input elements (g:textField, g:hiddenField, and some others) automatically set the id attribute of the generated HTML tag equal to the name attribute, unless the id attribute is explicitly given.
Is there any way to use those custom tags to produce an HTML tag without an id attribute? I tried setting the id attribute to an empty string but the generated code had the id set to the name.
I know I can do this with custom tags but I am wondering if there is a simpler way.
This doesn’t seem to be possible. The source code of the
FormTagLib.groovyclass shows that there is a flag that decides whether to writeidattributes identical to the name if an id was not given. Unfortunately it is turned on and not configurable from outside. See the following code:First, we have the source of
g:textFieldwhich callsfieldImplThe method
fieldImpl(full source available on Github) callsoutputAttributes. Note the third parameter which istrueoutputAttributes looks like this (abbreviated):
This method calls
outputNameAsIdIfIdDoesNotExist...which will generate the actual id. AsoutputAttribuesalways receivestrue, nothing can be done to overwrite it.