Skip to content
Snippets Groups Projects
Commit 66cf13d4 authored by David Sveningsson's avatar David Sveningsson
Browse files

fix: input hidden should not have label

fixes #53
parent 000affb8
No related branches found
No related tags found
1 merge request!305fix: input hidden should not have label
Pipeline #91787473 passed with warnings
......@@ -17,6 +17,11 @@ describe("rule input-missing-label", () => {
expect(report).toBeValid();
});
it('should not report input type="hidden" is missing label', () => {
const report = htmlvalidate.validateString('<input type="hidden" />');
expect(report).toBeValid();
});
it("should not report when input is nested inside label", () => {
const report = htmlvalidate.validateString("<label>foo <input/></label>");
expect(report).toBeValid();
......
......@@ -15,6 +15,14 @@ class InputMissingLabel extends Rule {
this.on("dom:ready", (event: DOMReadyEvent) => {
const root = event.document;
for (const elem of root.querySelectorAll("input, textarea, select")) {
/* <input type="hidden"> should not have label */
if (elem.is("input")) {
const type = elem.getAttributeValue("type");
if (type && type.toLowerCase() === "hidden") {
continue;
}
}
/* try to find label by id */
if (findLabelById(root, elem.id)) {
continue;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment