Jump to content

How to move placeholder to top on focus AND while typing


Recommended Posts

Hello @CoopperBackpack

You can insert this snippet of code into your submission form Header:

<style>
.cbFormFieldCell  {
 position: relative;
 width: 50%;
}

.cbFormFieldCell  .floating-label {
 position: absolute;
 color: gray;
 font-size: 13px;
 pointer-events: none;
 top: 11px;
 left: 20px;
 transition: 0.2s ease all;
}

.cbFormFieldCell  input:focus ~ .floating-label,
.cbFormFieldCell input:not(:focus):valid ~ .floating-label {
 top: 0px;
 left: 10px;
 font-size: 10px;
 opacity: 1;
 background-color: white;
 padding: 0 3px;
}
</style>

<script>
document.addEventListener("DataPageReady", placeholderHandler);

function placeholderHandler() {
 const labels = document.querySelectorAll('.cbFormLabelCell');
 const inputs = document.querySelectorAll('.cbFormFieldCell');

 for(let i = 0; i < labels.length; i++) {
  if (inputs[i].children[0].type === 'text') {  
   labels[i].children[0].classList.add("floating-label");
   inputs[i].children[0].setAttribute("required", true);
   inputs[i].appendChild(labels[i].children[0]);
   labels[i].remove();
  }
 }
 console.log(labels);
}
</script>

You also can customize the placeholder adjusting the properties in the style tag of the code.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...