Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7440135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:48:20+00:00 2026-05-29T10:48:20+00:00

I noticed that some of the Grails tags for generating input elements ( g:textField

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T10:48:22+00:00Added an answer on May 29, 2026 at 10:48 am

    This doesn’t seem to be possible. The source code of the FormTagLib.groovy class shows that there is a flag that decides whether to write id attributes 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:textField which calls fieldImpl

    def textField = { attrs ->
        attrs.type = "text"
        attrs.tagName = "textField"
        fieldImpl(out, attrs)
    }
    

    The method fieldImpl (full source available on Github) calls outputAttributes. Note the third parameter which is true

     def fieldImpl(out, attrs) {
        resolveAttributes(attrs)
        out << "<input type=\"${attrs.remove('type')}\" "
        outputAttributes(attrs, out, true)
        out << "/>"
    } 
    

    outputAttributes looks like this (abbreviated):

    void outputAttributes(attrs, writer, boolean useNameAsIdIfIdDoesNotExist = false) {
        attrs.remove('tagName') // Just in case one is left
        attrs.each { k, v ->
          ...
        }
        if(useNameAsIdIfIdDoesNotExist) {
            outputNameAsIdIfIdDoesNotExist(attrs, writer)
        }
    }
    

    This method calls outputNameAsIdIfIdDoesNotExist... which will generate the actual id. As outputAttribues always receives true, nothing can be done to overwrite it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I noticed that some PHP frameworks use exclusively lowercase true / false and others
Using the Grails YUI plugin, I've noticed that my GUI tags are replaced with
I've noticed that some static analyzers operate on source code, while others operate on
I've noticed that some generated classes only declare class properties/variables via @property, and don't
I noticed that some validation tools use the class attribute to pass options to
I've noticed that some web developers put IDs on scripts tags. For example: <script
I noticed that some elements have attributes which are boolean. I wonder why the
I noticed that some enumerations have None as a enumeration member. For example what
I noticed that some stylesheets have something like this: body { font-size: 62.5%/1.2em; }
I've noticed that some sites (usually banks) suppress the ability to paste text into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.