Commit 66cf13d4 authored by David Sveningsson's avatar David Sveningsson

fix: input hidden should not have label

fixes #53
parent 000affb8
Pipeline #91787473 passed with stages
in 7 minutes and 35 seconds
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment