[Web:S6853] "A form label must be associated with a control."

<ul class="ProviderType Checkboxing">
	<li th:each="type : ${ webData.enumsMap.get('Provider.Type') }">
		<input type="checkbox" th:id="${'chk_'+type}" name="providerType" th:value="${type}"/>
		<label th:for="${'chk_'+type}" th:text="${ #messages.msgOrNull('enum.Provider.Type.' + type) }"></label>

Although wrapping input with label can be a solution, having a label side by side with input control at th same level and adding for attribute to label is also a legal construct.

Rule number is printed with extremely small font, so I’m bringing here a screenshot.
Is there a chance to add a button “Copy rule ID” or make it a clickable and do a copy to clipboard in on-click even or something else to avoid typing it letter by letter?


Well, now it’s getting weird for me.
The input element is now wrapped with label and I’m still getting a warning.
I see it’s about “form label” and I don’t even know what that means.
When I open rule description, there are not enough examples to see what I’m doing wrong.

<label th:for="${'chk_'+type}" th:text="${ #messages.msgOrNull('enum.Provider.Type.' + type) }">
	<input type="checkbox" th:id="${'chk_'+type}" name="providerType" th:value="${type}"/>

1 Like


To make sure you’re experiencing this in the latest implementation of the rule, can you share your SonarLint version and/or if you’re in connected mode whether it’s to SonarCloud or SonarQube (and the SQ version)?


It’s not just a legal construct, it’s HTML’s most explicit way of connecting a label with an input element and it should definitely not trigger error messages.

What I don’t see in the code snippet, however, is the label text that would end up between the <label> and </label> tags. Would that be added by a different loop in the script?