Problem/Motivation

This came up on #1305882: drupal_html_id() considered harmful; remove ajax_html_ids to use GET (not POST) AJAX requests.

Would allow us to remove lots of #IDs that we never actually use otherwise, making form markup considerably lighter.

Proposed resolution

Make default label tag wrap the element rather than relying on the for attribute.

Remaining tasks

TBD.

User interface changes

TBD.

API changes

Markup change, but no API change as such.

Comments

Fabianx’s picture

mortendk’s picture

i like this idea a lot (big surprice ) the forms is a real pita to read (in viewsource as us theming boys n girls often do)
theres an issue about cleaning up the forms more #2502017: Form markup & CSS classname cleanup

mortendk’s picture

So theres a couple of things to consider here
1. Accesability - I remember there was issues way back in html4 days, but tbh thats outta my memory right now, but we need to look into that.
(http://webaim.org/techniques/forms/advanced)
2. Generally theming of forms is a pita - loads of things are going on but very little are visible for the naked eye in the templates.
3. If we change this it should be a solution thats generated in the twig templates, so its easy peasy to change it around.

karolus’s picture

This looks like a vast improvement over the D7 forms. Unless I have to do otherwise, I normally go with the Webform module to get around a lot of the hassle.

As for accessibility, it looks like ARIA offers a good method for now and the future, but what about backward compatibility?

cr0ss’s picture

From perspective of theming and js template frameworks:

<label>Label<input /></label>

brings some trouble(can't address styles to actual label text) without having text wrapped in own div.

catch’s picture

We can add a data selector to the label, and this will match the data selector being added by #1305882: drupal_html_id() considered harmful; remove ajax_html_ids to use GET (not POST) AJAX requests to the form element. That still takes the ID off the form element, and it will be something that can be reliably targeted - whereas form IDs can be completely randomized now.

LewisNyman’s picture

We would need to add another wrapper element around the label text in order to achieve the label-above/label-inline/label-hidden UI selections

catch’s picture

Just realised that after typing #6, so yes this would let us drop IDs from the form elements, but doesn't save any markup in the end.

mortendk’s picture

Status: Active » Closed (won't fix)

ok im gotta be a little harsh here - and set it to wont-fix - even that i would love to clean up everything ;) but removing the ID is a big nono when it comes to accessability, so we should not to the label wrap on an input field.

... What we should do instead is to make it easy for a template to do that if thats a thing somebody wants to do ;) which were opening up other tickets on