Coder Social home page Coder Social logo

Comments (3)

matthew-dean avatar matthew-dean commented on May 12, 2024

I discovered that, like #9, setting prioritize: 'placeholder' and inserting the text into the placeholder directly allowed this to work, but this still seems like bizarre behavior.

from float-labels.js.

pryley avatar pryley commented on May 12, 2024

Float-labels only extracts the text content of the label instead of the full html content, it does this to avoid possible compatibility issues with unforeseen LABEL markup. It also removes any existing asterisk or colon.

https://github.com/geminilabs/float-labels.js/blob/3c002f7fef1385d09c4d9c0080f0d63ef496bbf6/src/float-labels.js#L153-L156

Removing the asterisk from the label allows for more flexible styling options (see https://geminilabs.github.io/float-labels.js/), however, it's very easy to put back with CSS:

.fl-is-required label.fl-label::after {
    content: '\2009\002a';
}

from float-labels.js.

pryley avatar pryley commented on May 12, 2024

Ok I've released v3.2.0. This version improves the placeholder logic for SELECT fields and adds a customPlaceholder callback option. You can now do the following:

const floatlabels = new FloatLabels( '.form-1', {
    // append an asterisk to the labels of required fields
    customLabel: function( labelEl, el ) {
        return labelEl.textContent + ( el.getAttribute( 'required' ) !== null ? ' *' : '' );
    },
    // append an asterisk to the placeholders of required fields
    customPlaceholder: function( placeholderText, el ) {
        return placeholderText + ( el.getAttribute( 'required' ) !== null ? ' *' : '' );
    },
});

from float-labels.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.