[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>
	</li>
</ul>

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?

rule

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}"/>
</label>

Hi,

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)?

 
Thx,
Ann

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?

@ChristopheS
Oh my, 2 years later I’m answering :frowning:
Yes, the text is connected over CSS, “::before” and “content” because of SEO - on my other website I used some words such as “Name:”, “Category:” etc. for each product and sadly, after SEO analysis, those became my top keywords. Moving those to CSS is the way to hide them from plain HTML reading.

This code block also triggers the same warning:
(SonarLint 11.23.0.84403 inside Eclipse STS)

<td>
  <label for="VeganTrademark" class="Stamp VeganTrademark">
    <input type="checkbox"
      name="veganTrademark"
      id="VeganTrademark"
      style="width:24px; height:24px;"/>
  </label>
</td>

CSS to pair with code block:

.Stamp {
  display:block;
  padding:5px 10px;
  text-align:center;
  border-radius:10px;
  overflow:hidden;
  border:2px solid transparent;
  transition:200ms;
}
.Stamp::after {
  display:inline-block;
  vertical-align:middle;
  height:60px;
  margin-left:35px;
}
.Stamp.VLabel::after {
  width:46px;
  content:var(--v-label); /* SVG */
}
.Stamp.VeganTrademark::after {
  width:75px;
  content:var(--vegan-trademark); /* SVG */
}
.Stamp:hover {
  background-color:#f8f8f8;
  border:2px solid #d8d8d8;
}

Hi,

The current version of SonarQube for Eclipse (formerly SonarLint) is 12.2.1. It likely is, but I need to dot my i’s, so can you upgrade and see if this is still replicable?

 
Thx,
Ann