Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for duplicate id attributes in HTML #5326

Merged
merged 8 commits into from
Dec 30, 2024
Merged

Conversation

quis
Copy link
Member

@quis quis commented Dec 11, 2024

It’s invalid HTML to have multiple elements with the same id attribute. Plus it can cause trouble for Javascripts, and make anchor linking unpredictable.

@quis quis changed the title Check for duplicate id attributes in HTML Check for duplicate id attributes in HTML Dec 11, 2024
@quis quis force-pushed the check-for-duplicate-ids branch 3 times, most recently from 1d71e7b to a67425b Compare December 13, 2024 16:21
@quis quis force-pushed the check-for-duplicate-ids branch 2 times, most recently from 0fe71e5 to 4fa35a9 Compare December 27, 2024 10:16
quis added 8 commits December 27, 2024 10:17
It’s invalid HTML to have multiple elements with the same `id`
attribute. Plus it can cause trouble for Javascripts, and make anchor
linking unpredictable.
This wasn’t doing anything styling-wise or functionality-wise, and it had
the same ID as its parent element
I think we used to have this as a target for some ARIA attributes, but
since moved way from using those here.
Because we are rendering the same form multiple times on one page we
need to make sure each time the hidden field is rendered it gets a
different ID.
Where the table rows don’t need IDs, let’s not show them
We’re not relying on these IDs being fixed elsewhere in the tests, so
let’s make them random.
Functional tests still need these on the page:
https://github.com/alphagov/notifications-functional-tests/blob/c9549ded6ab64ea61ba812a41cd7153541ceb784/tests/pages/pages.py#L917

This gives us a way of having the IDs in test fixtures still be
deterministic (up to single digits in base 16), but also unique
@quis quis force-pushed the check-for-duplicate-ids branch from 4fa35a9 to 125ed67 Compare December 27, 2024 10:22
@quis quis marked this pull request as ready for review December 27, 2024 10:22
@quis quis merged commit d0e07da into main Dec 30, 2024
3 checks passed
@quis quis deleted the check-for-duplicate-ids branch December 30, 2024 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants