Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The for attribute of the label element must refer to a non-hidden form control

I have some errors in my code Here is my error:

The for attribute of the label element must refer to a non-hidden form control.

And myd code:

<form action="/search">
  <span class="input input--hoshi search-wrapp main-page-open" style="display:block">
    <input class="input__field input__field--hoshi" type="text" id="search" name="keyword" placeholder="Search..."/>
    <label class="input__label input__label--hoshi input__label--hoshi-color-2" for="input-5">
      <!--<span class="input__label-content input__label-content-hoshi">Search...</span>-->
    </label>
    <span class="icon-serch"></span>
  </span>
  <input id="search-btn" type="submit" style="display: none;"/>
</form>

What is wrong with it? Thanks!

like image 653
Vlad Avatar asked Jul 25 '16 13:07

Vlad


People also ask

What does for attribute used for inside label?

The for attribute is an allowed attribute for <label> and <output> . When used on a <label> element it indicates the form element that this label describes. When used on an <output> element it allows for an explicit relationship between the elements that represent values which are used in the output.

Why should the value of the for attribute of label tag be same as the ID of the corresponding?

Explanation: The for property is used to associate a label with a certain form control. The value of the for attribute must match the value of the form control's id attribute. The for property is used to associate a label with a certain form of control.

What is form label element?

The <label> HTML element represents a caption for an item in a user interface.


1 Answers

The label for attribute must contain the input id value

<label for="foo">Foo:</label>
<input id="foo">

To omit the for and id attributes all-together, put input inside label

<label>
    Foo: <input name="foo">
</label>

Also note, that input cannot be hidden <input type="hidden">, however it can be styled as hidden <input style="display:none">

like image 158
Igor Sukharev Avatar answered Oct 23 '22 05:10

Igor Sukharev