Bootstrap 5 floating labels

Bootstrap 5 floating labels

Loren MaxwellLoren Maxwell Posts: 300Questions: 69Answers: 9
edited September 17 in Editor

I was interesting in incorporating the floating labels from Bootstrap 5:
https://getbootstrap.com/docs/5.0/forms/floating-labels/

But it requires an unconventional order for the input and the label (input first) and also a "for" attribute for the label.

<div class="form-floating mb-3">
  <input type="email" class="form-control"
        id="floatingInput" placeholder="name@example.com">
  <label for="floatingInput">Email address</label>
</div>

Offhand I don't see a way to implement this with Editor, even when making a plugin, because there's no a way to control the order of the label or add an attribute to it.

Am I mistaken or looking in the wrong place?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 54,743Questions: 1Answers: 8,565 Site admin
    Answer ✓

    You are correct, there isn't an out of the box way to do this in Editor I'm afraid (it does look super cool though!).

    However, what could be done is to use the field().node() method to get the container for the input in Editor and then mode the DOM elements around (and add attributes) using jQuery / DOM methods. This is the structure that Editor uses for the input elements. So the label could be moved after the input.

    Interested to hear how you get on with this - it could be something we add as a toggle option to the Bootstrap integration.

    Allan

  • Loren MaxwellLoren Maxwell Posts: 300Questions: 69Answers: 9

    Thanks, @allan -- I'm not sure I'll end up working on it, but if I do I'll certainly post the solution.

    And yes -- please add as a toggle option for Bootstrap styling! Aside from being an attractive interface, it maximizes the form space.

Sign In or Register to comment.