Grails

"label for" should reference an 'id' not a 'name' in HTML

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 0.3.1
  • Fix Version/s: 0.6-RC1
  • Component/s: Scaffolding
  • Labels:
    None

Description

Scaffolding generates a LABEL element and an INPUT element. The LABEL 'for' attribute references the INPUT 'name' attribute but should reference the INPUT 'id' attribute instead.

Fix: add an 'id' attribute to the INPUT element and use the same attribute value for 'id' as the one used for the 'name' attribute.

Current generation:
<label for='name'>Event Name:</label>
<input type='text' name='name' value='${event?.name}'/>

Desired:
<label for='event'>Event Name:</label>
<input type='text' id='event' name='event' value='${event}'/>

See HMTL specifications:

<http://www.w3.org/TR/html4/interact/forms.html#h-17.9.1>

17.9.1 The LABEL element

<!ELEMENT LABEL - - (%inline* -(LABEL) – form field label text -->
<!ATTLIST LABEL
%attrs; – %coreattrs, %i18n, %events –
for IDREF #IMPLIED – matches field ID value –
accesskey %Character; #IMPLIED – accessibility key character –
onfocus %Script; #IMPLIED – the element got the focus –
onblur %Script; #IMPLIED – the element lost the focus –
>

Start tag: required, End tag: required

Attribute definitions

for = idref [CS]
This attribute explicitly associates the label being defined with another control. When present, the value of this attribute must be the same as the value of the id attribute of some other control in the same document. When absent, the label being defined is associated with the element's contents.

Activity

Hide
Marc Guillemot added a comment -

I've faced the same problem today and have started looking at the source. I suppose that the ids have been once correctly generated when the <label for...> have been added. Due to missing tests, this is not the case anymore.

Fixing this involves adaptation of the form tags. For instance a Currency is rendered in gsp with something like:
<g:currencySelect name='currency' value='${test?.currency}'></g:currencySelect>

To fix this issue, the currencySelect should generate automatically an id or accept an attribute for that.

I bring the discussion to the dev mailing list

Show
Marc Guillemot added a comment - I've faced the same problem today and have started looking at the source. I suppose that the ids have been once correctly generated when the <label for...> have been added. Due to missing tests, this is not the case anymore. Fixing this involves adaptation of the form tags. For instance a Currency is rendered in gsp with something like: <g:currencySelect name='currency' value='${test?.currency}'></g:currencySelect> To fix this issue, the currencySelect should generate automatically an id or accept an attribute for that. I bring the discussion to the dev mailing list
Hide
Drew Varner added a comment -

My patch for GRAILS-724 fixes some of this, though I can't say it takes care of all occurences.

Show
Drew Varner added a comment - My patch for GRAILS-724 fixes some of this, though I can't say it takes care of all occurences.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: