Topic: Form labels not functioning
bsteinrock.dev asked 4 years ago
Expected behavior I am using the md-form inputs, and labels. I am trying to get them to work as they do in examples where the labels float to the top when active. Actual behavior The labels don't move at all, they change color when selected but that's all. When you type something into the textbox the text shows behind the label. I created a snippet that works as expected and then copied it into my project and it doesn't work. I have other components working as expected, the forms seem to be the one thing don't function as they should. I am using MDB 5 pro. Here is a sample directly from my code. when you click into the text box, it hightlights as it should but the label itself is static. i have warnings in the css file, but no errors in the project or chrome dev tools. I'm at a loss. Resources (screenshots, code snippets etc.)
<div class="md-form mb-0">
<input type="text" id="senderLast" class="form-control">
<label for="senderLastName">Last Name</label>
</div>
Andrew Ford pro premium priority answered 4 years ago
The ID of <input>
has to match the value of your for=""
attribute.
Andrew Ford pro premium priority commented 4 years ago
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/label
To associate the with an element, you need to give the an id
attribute. The then needs a for
attribute whose value is the same as the input's id
.
Tomek Makowski staff commented 4 years ago
@Andrew Ford thats right. @bsteinrock.dev, is the problem still present?
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Answered
- User: Free
- Premium support: No
- Technology: MDB jQuery
- MDB Version: 4.19.1
- Device: Laptop
- Browser: chrome
- OS: windows
- Provided sample code: No
- Provided link: No